Cheat Sheet

C# 2008 For Dummies Cheat Sheet

C# 2008 is an awesome programming language. Discover the operators you need to perform your functions and how to declare and use variables like integers, floating points, and others. Also take a look at how to control program flow in C# 2008.

Operators in C# 2008

In order to perform operations in C# 2008, you need, well…operators. The following chart shows you these operators. These symbols determine which operations to carry out in an expression:

Precedence

Operators

Cardinality

Associativity

High

() [] . new typeof

Unary

Left to right

*

! ~ + – ++ — (cast)

Unary

Left to right

*

* / %

Binary

Left to right

*

+ –

Binary

Left to right

*

< <= > >= is as

Binary

Left to right

*

== !=

Binary

Left to right

*

&

Binary

Left to right

*

^

Binary

Left to right

*

|

Binary

Left to right

*

&&

Binary

Left to right

*

||

Binary

Left to right

*

?:

Ternary

Right to left

Low

= *= /= %= += -= &= ^= |= <<= >>=

Binary

Right to left

C# 2008 Integer Variable Types

Each variable has a fixed type in C#, and integer (int) variable types are limited to whole numbers. C# has several other integer variable types, shown in this chart:

C# 2008 Floating Point Variable Types

C# distinguishes real numbers, which come in two styles: floating point and decimal. Floating point is the most common and floating-point variables are assigned. This chart describes the two floating-point variables in C#:

Type

Size (bytes)

Range

Accuracy

In Use

float

8

1.5 * 10-45 to 3.4 * 1038

6-7 digits

float f = 1.2F;

double

16

5.0 * 10-324 to 1.7*10308

15-16 digits

double d = 1.2;

Controlling Program Flow in C# 2008

C#, like most programming languages, can make decisions. You can create a C# program that reads your data and automatically performs the tasks you need. Depending on the attributes of the information it’s processing, a C# program can skip sections of code, run other C# programs (subroutines), and repeat sections of code just as many times as necessary to process the data. If you’ve used other programming languages, these powerful functions will be familiar friends:

Dummies Insider

Sign up for insider news on books, authors, discounts and more content created just for you.