C# Simplified - Different Types of Data Types
(Page 2 of 5 )
The .NET Framework provides lot of data types which you can use for developing applications. Since these data types are provided by the Common Language Runtime (CLR), all .NET languages such as C#, Visual Basic .NET can take advantage of them. A complete list of all data types and its range values are given in Table 1.
Table 1 List of Data Types
| Data Type Prefix | .NET Data | Type Min Value | Max Value |
| sbyte | System.Sbyte | -128 | 127 |
| byte | System.Byte | 0 | 255
|
| short | System.Int16 | -32,768 | 32,767
|
| ushort | System.UInt16 | 0 | 65,535 |
| int | System.Int32 | -2,147,483,648 | 2,147,483,647 |
| uint | System.UInt32 | 0 | 4,294,967,295 |
| long | System.Int64 | -9,223,372,036,854,775,808 | 9,223372,036,854,775,808 |
| ulong | System.UInt64 | 0 | 18,446,744,073,709,551,615 |
| char | System.Char | 0 | 65,535 |
| float | System.Single | 1.5 x 10^-45 | 3.4 x 10^38 |
| double | System.Double | 5.0 x 10-324 | 1.7 x 1010308 |
| bool | System.Boolean | False (0) | True (1) |
| decimal | System.Decimal | 1.0 x 10-28 | 7.9 x 1028
|
Operators
With the help of operators, you can manipulate values and perform arithmetical operations. For instance, if you have to add three numbers you must use the addition (+) symbol. In the same way, if you have to multiply three numbers, you must use the * symbol. In programming parlance, these symbols are known as Operators. You will use them extensively when you develop applications such as calculator.
C# offers a wide variety of operators which can be used for various purposes. Table 2 lists all the available operators in C# in the order of their precedence.
Table 2 List of Operators
| Name of the Operator | Description |
| Primary Operators | () . [] x++ x-- new typeof sizeof checked unchecked |
| Unary | + - ! - ++x --x |
| Multiplicative | * / % |
| Additive | + - |
| Shift | << >> |
| Relational | < > <= >= is |
| Equality | = = != |
| Bitwise AND | & |
| Bitwise XOR | ^ |
| Bitwise OR | | |
| Conditional AND | && (Used for evaluating conditions using if-else) |
| Conditional OR | || (Used for evaluating conditions using if-else) |
| Conditional | ?: (Used for evaluating conditions instead of if-else) |
| Assignment | = *= /= %= += -= <<= >>= &= ^= != |
Let us now look at a simple C# program which illustrates the functioning of one of the operators listed in the table above.
Listing 1.2
001: using System;
002:
003: class Oper
004: {
005: public static void Main()
006: {
007:
008: int x = 50;
009: int y = 100;
010:
011: if ((x<y && y>x)) {
012:
013: Console.WriteLine("X is less than Y");
014: }
015:
016: else {
017:
018: Console.WriteLine("Condition not satisfied");
019: }
020:
021: }
022: }
In the above listing, the condition in line 11 will execute only when both the parameters are correct. If any one of the parameters is false the statements inside the else part will be printed as output.
In the next section, you will learn about the concept of value and reference types in C#.
Next: Value Types and Reference Types >>
More C# Articles
More By Anand Narayanaswamy