Scope: The scope of this article is up to title and to describe it in practically behavior.
Before, we go further to know about the C# data type, let understand the two important types i.e. Value type and reference type.
The Value type stores value directly rather than reference type stores a reference to that value. In memory, Value type stores in stack and reference type stores in heap.
Now, let us take a look on data types
C#:Data Types The following table shows the detailed overview of C#:Data Types
Name | Relevant
CTS Type | Description | Range | Type | Example | Min. | Max | Value | Ref. | sbyte | System.Sbyte | Signed Integer [8-bits] | -128 | 127 | Yes | No | sbyte i; | short | System.Int16 | Signed Integer [16-bits] | 32,768 | 32,767 | Yes | No | short i; | int | System.Int32 | Signed Integer [32-bits] | -2,147,483,648 | 2,147,483,647 | Yes | No | int i; | long | System.Int64 | Signed Integer [64-bits] | -9223372036854775808 | 9223372036854775807 | Yes | No | long i = 1234L; | byte | System.Byte | Unsigned Integer [8-bits] | 0 | 255 | Yes | No | byte i; | ushort | System.UInt16 | Unsigned Integer [16-bits] | 0 | 65,535 | Yes | No | ushort i; | uint | System.UInt32 | Unsigned Integer [32-bits] | 0 | 4,294,967,295 | Yes | No | uint i = 1234U; | ulong | System.UInt64 | Unsigned Integer [64-bits] | 0 | 18446744073709551615 | Yes | No | ulong i = 1234UL; | float | System.Single | Single precision floating point [32-bits] | +1.5 x 10-45 | +3.4 x 1038 | Yes | No | float i; | double | System.Double | Double precision floating point [64-bits] | +5.0 x 10-324 | +1.7 x 10308 | Yes | No | double i; | decimal | System.Decimal | High precesion decimal notation [128-bits] | +1.0 x 10-28 | +7.9 x 1028 | Yes | No | decimal i=12.45m; | bool | System.Boolean | dedicated to boolean type [true ot false] | | | Yes | No | bool i; | char | System.Char | Single [64-bit unicode character] | | | Yes | No | char i; | object | System.Object | The main type or mother type, all other CTS types derived from it | | | No | Yes | object i; | string | System.String | Represents Unicode Characters | | | No | Yes | string s; |
The following examples send the output of data types:
/* This Example is a part of different * examples shown in Book: * C#2005 Beginners: A Step Ahead * Written by: Gaurav Arora * Reach at : gaurav.aroraose@yahoo.co.in*/
// File name : datatypesCS.cs
using System;
namespace CSharp.AStepAhead.datatypesCS {
public class datatypesCS {
static void Main() { Console.WriteLine("Data Types and their range(s) in C# : "); Console.WriteLine("sbyte: {0} to {1}", sbyte.MinValue, sbyte.MaxValue); Console.WriteLine("byte: {0} to {1}", byte.MinValue, byte.MaxValue); Console.WriteLine("short: {0} to {1}", short.MinValue, short.MaxValue); Console.WriteLine("ushort: {0} to {1}", ushort.MinValue, ushort.MaxValue); Console.WriteLine("int: {0} to {1}", int.MinValue, int.MaxValue); Console.WriteLine("uint: {0} to {1}", uint.MinValue, uint.MaxValue); Console.WriteLine("long: {0} to {1}", long.MinValue, long.MaxValue); Console.WriteLine("ulong: {0} to {1}", ulong.MinValue, ulong.MaxValue); Console.WriteLine("float: {0} to {1}", float.MinValue, float.MaxValue); Console.WriteLine("double: {0} to {1}", double.MinValue, double.MaxValue); Console.WriteLine("decimal: {0} to {1}", float.MinValue, float.MaxValue); //Recognize to user the output Console.WriteLine("Hit enter to terminate!"); Console.Read(); return; } } }
Escape sequence
C# has escape sequences for better formatting results like other languages:
C#:Escape Sequences Like other languages C# also have esape sequences, following table describes all:
Escape Sequence | Meaning | \' | Single quote | \" | Double quote | \\ | Backslash | \0 | Null | \a | Alert | \b | Backspace | \f | FormFeed | \n | Newline | \r | Carriage return | \t | Tab character | \v | Vertical tab |
The following program tells about all escape sequences
/* This Example is a part of different * examples shown in Book: * C#2005 Beginners: A Step Ahead * Written by: Gaurav Arora * Reach at : gaurav.aroraose@yahoo.co.in*/
// File name : escapesequence.cs
using System;
namespace CSharp.AStepAhead.escapesequence {
class escapesequence { static void Main() { string str = "This is : "; Console.WriteLine("{0} \'Single quote",str); Console.WriteLine("{0} \" Double quote", str); Console.WriteLine("{0} \\ Backslash", str); Console.WriteLine("{0} \0 Null", str); Console.WriteLine("{0} \a Alert", str); Console.WriteLine("{0} \b Backspace", str); Console.WriteLine("{0} \f Form feed", str); Console.WriteLine("{0} \n Newline", str); Console.WriteLine("{0} \r Carriage return", str); Console.WriteLine("{0} \t Tab", str); Console.WriteLine("{0} \v Vertical Tab", str); return; } } }
For more details, visit http://www.msdotnetheaven.com/ChaptersCsharp/csharplanguagei.htm
|
No responses found. Be the first to respond and make money from revenue sharing program.
|