ankitweblogic logo
W e b t u t o r i a l s

Console C#.Net Tutorial

Visual Studio.NET IDE

Define C#.NET

C# Comment

C# Variables

C# Data Types

C# Escape Sequence

C# Operators


Format String

Operator Precedence

C# Keywords

Constant Variable

Type Conversion

Flow Control

Exercise Loops & Nested Loop

C# Arrays

C# Strings

User-Define Methods

Variable Scope

C# Enumerations

C# Structure

C# Exception Handling

Object Oriented Programming

C# Classes

Constructor & Destructor

C# Inheritance

C# Polymorphism

C# Operator Overloading

C# Method Overriding

C# Interface

Abstract Classes & Methods

Sealed Classes, Methods

C# Properties

C# Indexer

C# Delegates

C# Generics

C# Collection


C# Data Types

The concept of data type is use to define a variable before using it. Data type defines the type of data entered by the user. In C#, data types are categorized into the following types:
1. Value Type: Value type variables can be assigned a value directly. They are derived from the class System.ValueType.
a. Integer Data Type: Contain only numbers, Decimal numbers are not allow. Integer data type is further classified into different categories:

TypeAliased Signed/ UnsignedSuffixSize Range
sbyteSystem.SByte SignedNone1 byte-128 to 127
byteSystem.Byte UnsignedNone1 byte0 to 255
shortSystem.Int16 SignedNone2 bytes-32768 to 32767
ushortSystem.UInt16 UnsignedNone2 bytes0 to 65535
intSystem.Int32 SignedNone4 bytes-2147483648 to 2147483647
uintSystem.UInt32 UnsignedU or u4 bytes0 to 4294967295
longSystem.Int64 SignedL or l8 bytes-263 to 263-1
ulongSystem.UInt64 UnsignedUl,UL,ul,
8 bytes 0 to 264-1

b. Floating-point: Floating-point data types are used to store decimal values. Floating point is further classified into different categories.

Type Aliased Suffix Size Range
float /single System.Single F or f 4 byte 1.5 x 10-45 to 3.4 x 1038 with precision of 7 digits
Double System.Double None, d or D 8 byte 5.0 x 10-324 to 1.7 x 10308 with precision of 15-16 digits
Decimal System.Decimal M or m 16 bytes 1.0 x 10-28 to 7.9 x 1028 with precision of 28-29 digits

c. Character Data Type: Use to Store alphabet, number, special character.

Type Aliased Suffix Allowed Values
Char System.Char None Single Unicode character, stored as integer between 0 to 65535
Bool System.Boolean None Boolean values, true or false, Default value is false.

2. Reference Type: The reference types do not contain the actual data stored in a variable, but they contain a reference to the variables.

Type Aliased Suffix Allowed Values
String System.String None A sequence of characters

Object Type: The Object Type is the base class for all data types. In object data types any type of value can be assigned.

Comparing Value type and Reference types
1. Value type stores the value of their data.
Reference types store the address of their data.
2. In value type, creating new object occupy different memory location.
In Reference type, creating a new object does not occupy a new memory location rather it shares the same memory location of existing object.
3. In value type change in one object does not reflects other object.
In Reference type, change of value in one object reflects another object.