03.11.2016 Views

Beginning ASP.NET 4.5 in CSharp and VB Opsylum

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Statements x 161<br />

Dim someNumber4 As Integer = 3<br />

someNumber1 += 3 ' Results <strong>in</strong> someNumber1 hav<strong>in</strong>g the value 6<br />

someNumber2 -= 3 ' Results <strong>in</strong> someNumber2 hav<strong>in</strong>g the value 0<br />

someNumber3 *= 3 ' Results <strong>in</strong> someNumber3 hav<strong>in</strong>g the value 9<br />

someNumber4 /= 3 ' Results <strong>in</strong> someNumber4 hav<strong>in</strong>g the value 1<br />

C#<br />

<strong>in</strong>t someNumber1 = 3;<br />

<strong>in</strong>t someNumber2 = 3;<br />

<strong>in</strong>t someNumber3 = 3;<br />

<strong>in</strong>t someNumber4 = 3;<br />

someNumber1 += 3; // Results <strong>in</strong> someNumber1 hav<strong>in</strong>g the value 6<br />

someNumber2 -= 3; // Results <strong>in</strong> someNumber2 hav<strong>in</strong>g the value 0<br />

someNumber3 *= 3; // Results <strong>in</strong> someNumber3 hav<strong>in</strong>g the value 9<br />

someNumber4 /= 3; // Results <strong>in</strong> someNumber4 hav<strong>in</strong>g the value 1<br />

C# also enables you to <strong>in</strong>crease a variable’s value by 1 us<strong>in</strong>g the ++ operator, like this:<br />

C#<br />

<strong>in</strong>t someNumber = 3;<br />

someNumber++; // Results <strong>in</strong> someNumber hav<strong>in</strong>g the value 4<br />

This construct is used often <strong>in</strong> loops, as you’ll see later <strong>in</strong> the chapter.<br />

Both languages also use arithmetic assignment operators to concatenate str<strong>in</strong>g values, as you’ll see<br />

shortly.<br />

Another common set of operators is the comparison operators, which enable you to compare values.<br />

Comparison Operators<br />

Just as with the arithmetic operators, <strong>VB</strong>.<strong>NET</strong> <strong>and</strong> C# each have their own set of comparison<br />

operators to compare one value to another. A comparison operator always compares two values or<br />

expressions <strong>and</strong> then returns a boolean value as the result. The follow<strong>in</strong>g table lists the most common<br />

comparison operators.<br />

<strong>VB</strong>.<strong>NET</strong> C# Usage<br />

= == Checks if two values are equal to each other<br />

!= Checks if two values are not equal<br />

< < Checks if the first value is less than the second<br />

> > Checks if the first value is greater than the second<br />

= Checks if the first value is greater than or equal to the second<br />

Is is In <strong>VB</strong>.<strong>NET</strong>: Compares two objects. In C#: Checks if a variable is of a<br />

certa<strong>in</strong> type

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!