Mega Code Archive

 
Categories / C# / Data Types
 

The use of the cast operator

/* Mastering Visual C# .NET by Jason Price, Mike Gunderloy Publisher: Sybex; ISBN: 0782129110 */ /*   Example2_3.cs shows the use of the cast operator,   and how information loss can occur when explicitly   converting a variable of one type to another */ public class Example2_3 {   public static void Main()   {     short myShort = 17000;     System.Console.WriteLine("myShort = " + myShort);     int myInt = myShort;     System.Console.WriteLine("myInt = " + myInt);     myShort = (short) (myInt * 2);     System.Console.WriteLine("myShort = " + myShort);   } }