The use of the cast operator : Casting Conversions : Data Types C# Source Code


Custom Search

C# Source Code » Data Types » Casting Conversions »

 

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);

  }

}

           
       
    
   
  
   







HTML code for linking to this page:

Follow Navioo On Twitter

C# Source Code

 Navioo Data Types
» Casting Conversions