Type Casting in C#

Type Casting is a concept of converting one data type into another data type.C# supports two types of type casting. They are..
  1. Implicit Type Casting
  2. Explicit Type Casting
C # supports three types of explicit type castings: They are
  1. C++ style of type casting
    • Eg.,: int i = 100;
             byte b = (byte) i;
  2. Parsing: Parse () is used to convert string data type into any data type.
  3. E.g.: int i = int.Parse (txtName.Text);
  4. Converting: Convert is used to convert any data type into any required data type.
  5. E.g.: Convert.ToInt32();
    Methods of Convert class:
    • Convert.ToChar()
    • Convert.ToByte()
    • Convert.ToFloat()
    • Convert.ToINT16()    //for Short Int
    • Convert.ToINT32()   //for int
    • Convert.ToINT64()   //for long

0 comments :

Post a Comment

> Related Posts with Thumbnails
 

Copyright © 2012. GS dot net - All Rights Reserved - Design by BTDesigner - Proudly powered by Blogger