Cheat Sheet

C# 2008 For Dummies

From C# 2008 For Dummies by Stephen R. Davis, Chuck Sphar

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:

Type Size (bytes) Range In Use
sbyte 1 -128 to 127 sbyte sb = -12;
byte 1 0 to 255 byte b = 12;
short 2 -32,768 to 32,767 short sn = -123;
ushort 2 0 to 65,535 ushort usn = 123;
int 4 -2,147,483,648 to 2,147,483,647 int n = 123;
uint 4 0 to 4,294,967,295 uint un = 123U;
long 8 -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 - “a whole lot” long l = 123L;
ulong 8 0 to 18,446,744,073,709,551,615 long ul = 123UL;

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:

image0.jpg
  • Add a Comment
  • Print
  • Share
blog comments powered by Disqus
Advertisement

Inside Dummies.com

Dummies.com Sweepstakes

Win $500. Easy.