An important distinction that is often unmentioned when talking about C# is that most of the objects and types used are not native to C# itself. They are defined in the assemblies that are part of the .NET Framework. They're no different than the types you or I can create. But a few of these types are special. These are the "built in types," often called "primitive types,".
These basic types are the most important of all to learn, because they are the foundation of everything you will program. These types are the most basic expression of data.
Basic built-in types:
Examples
These basic types are the most important of all to learn, because they are the foundation of everything you will program. These types are the most basic expression of data.
Basic built-in types:
1. Boolean type – Only true or false
This is the simplest possible type. It can only hold one of two values: true or false (1 or 0, if you prefer to think of it that way).
eg : bool b;
2. Integral Types - sbyte, byte, short, ushort, int, uint, long, ulong, char
Integral types are all integers of varying capacities. There are two factors that define what each can hold: the size of the memory allocated, and whether or not the integer is "signed." Signed defines whether or not the type can hold negative values.
Integral types are all value types. Variables declared as any of these types hold values directly, not references to values.
eg : int i;
3. Floating Types – float and double
Floating point types are all real numbers of varying range and precision. Both of these values are very important to understand! Range defines the maximum and minimum values the variable can hold, and precision determines the number of significant figures the variable holds.
eg : float f = 3.141f;
4. Decimal Types
The decimal keyword indicates a 128-bit data typr. Compared to floating-point types,the decimal type has more precision and a smaller range.
eg : decimal d = 3.141m;
5. String Type
The String Type allows you to assign any string values to a variable. The string type is an alias for the System.String class. It is derived from object type.
eg : String name =”sandhya”;
Escape Sequences in C#
Character combinations consisting of a backslash (\) followed by a letter or by a combination of digits are called "escape sequences." To represent a newline character, single quotation mark, or certain other characters in a character constant, you must use escape sequences.
Escape sequences are typically used to specify actions such as carriage returns and tab movements on terminals and printers. They are also used to provide literal representations of nonprinting characters and characters that usually have special meanings, such as the double quotation mark (").
Examples
| \a | Bell (alert) |
| \b | Backspace |
| \f | Formfeed |
| \n | New line |
| \r | Carriage return |
| \t | Horizontal tab |
| \v | Vertical tab |
| \' | Single quotation mark |
| \" | Double quotation mark |
| \\ | Backslash |
Console.WriteLine(name ); // output “sandhya”
Verbatim Literal:
Verbatim Literal is a string with an @ symbol prefix, as in @“Hello".
Verbatim literals make escape sequences translate as normal printable characters to enhance readability.
Example:
Without Verbatim Literal : “C:\\Pragim\\DotNet\\Training\\Csharp” – Less Readable
With Verbatim Literal : @“C:\Pragim\DotNet\Training\Csharp” – Better Readable
0 comments:
Post a Comment