Chapter OneLesson Three
DATA TYPES
© www.waxkabaro.com
What is Data type?
Data types are sets (ranges) of values that have similarcharacteristics.
For instance byte type specifies the set of integers in therange of [0 … 255].
© www.waxkabaro.com
Types
Basic data types in C# are distributed into the followingtypes:
- Integer types (Whole Number without Negative) –short(int16), int(int32) long(int64);
- Real floating-point types(Decimal number with orwithout  negative and ) – float, double;
- Real type with decimal precision – decimal;
- Boolean type – bool (True or False);
- Character type – char;
- String – string;
- Object type – object.
© www.waxkabaro.com
Integer types- examples
        {
            Int16 centuries = 20;
            Int16 years = 2000;
            Int32 days = 730480;
            Int32 hours  = 17531520;
            Int32 minutes =1051891200;
            Int64 seconds = 63113472000;
            Int64 milliseconds = 3786808320000;
 
 
            Console.WriteLine(centuries + " centuries are " + years +" years, or " + days + " days, or " + hours + "hours or " + minutes + " minutes or " + seconds +" seconds or " + milliseconds +  " millisoconds ");
            Console.ReadLine();
        }
© www.waxkabaro.com
Double Types
Double and Decimal types are used for numbers withdecimal numbers and negative number
Double: It is also called double precision real number and isa 64-bit type with a default value of 0.0d and 0.0D (thesuffix 'd' is not mandatory because by default all realnumbers in C# are of type double).
© www.waxkabaro.com
This type has precision of 15 to 16 decimal digits. The range of values, whichcan be recorded in double (rounded with precision of 15-16 significantdecimal digits),
© www.waxkabaro.com
Decimal type
The type of data for real numbers with decimal precision inC# is the 128-bit type decimal. It has a precision from28 to 29 decimal places.
© www.waxkabaro.com
Example – Double Vs Decimal
static void Main(string[] args)
         {  int a = 1;
            int b = 2;
            decimal PI = 3.142857142857143m;
            double pi = 3.142857142857143;
            Console.WriteLine(PI);
            Console.WriteLine(pi);
 
            Console.ReadLine();
        }
© www.waxkabaro.com
Next Lesson
Boolean Type
© www.waxkabaro.com