
54Microsoft Visual Studio 2010: A Beginner’s Guide
Consistent with Table
Expressions
When performing computations in your code, you’ll do so through expressions, which are a combination of variables, operators (such as addition or multiplication), or referencing other class members. Here’s an expression that performs a mathematical calculation and assigns the result to an integer variable:
C#:
int result = 3 + 5 * 7;
VB:
Dim result As Int32 = 3 + 5 * 7
A variable that was named result in this example is a C# type int or a VB type Int32, as specified in Table
You can modify the order of operations with parentheses. Here’s an example that adds
3 to 5 and then multiplies by 7:
C#:
int differentResult = (3 + 5) * 7;
VB:
Dim differentResult As Int32 = (3 + 5) * 7
Because of the grouping with parentheses, differentResult will have the value 56 after this statement executes.