All Type Coding

Search Here

Built-in Data Types in c#

C# is a strongly-typed language. Before a value can be stored in a variable, the type of the variable must be specified. The type must be specified both for simple, built-in types such as an int, and for complex or custom types such as XmlDocument.
The CSharp type system contains three Type categories
They are: 
1-Value Types: The Value Types store the data The Value Types derived from System.ValueType The value types directly contain data. for examples are int, char, and float When you declare an int type, the system allocates memory to store the value.
Boolean type – Only true or false 
Integral Types - sbyte, byte, short, ushort, int, uint, long, ulong, char
Floating Types – float and double
Decimal Types 
if you want  get the exact size of a type or a variable on a particular platform, you can use the sizeof method. 
The syntax: sizeof(type) 
for Example:

using System;
   class Program 
   {
      static void Main(string[] args)
      {
         Console.WriteLine("Size of int: {0}", sizeof(int));
         Console.ReadLine();
      }
   }

}

Output :
Size of int: 4

2- Reference Types: Reference Types store references to the actual data.the Reference Types derived from System.Object .for Example of built-in reference types are: object, dynamic, and string.
Example of object:
object obj;

obj = 10;

Example of dynamic:
dynamic <variable_name> = value;
For example:

dynamic a = 10;

string: 
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

Example of string:
String str = "Tutorials Point";
or
@"ALLTYPECODING";


3- Pointer Types: Pointer Types variable use only in unsafe mode.
Syntax: pointer type is:


type* identifier;
For example,
char* abcd;

int* pic;

Escape Sequences in C#
http://msdn.microsoft.com/en-us/library/h21280bw.aspx

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. 

No comments :

Post a Comment