Conversions between Simple Types

image_pdfimage_print
   
 

using System;

public class MainClass {
    public static void Main() {

        double d = 2.9;
        Console.WriteLine((int)d);                   // double-->int; prints 2 
        Console.WriteLine((int)(-d));                // double-->int; prints -2 
        uint seconds = (uint)(24 * 60 * 60);         // int-->uint 
        double avgSecPerYear = 365.25 * seconds;     // I uint-->double 
        float f = seconds;                           // IL uint-->float 
        long nationalDebt1 = 99999999999999;
        double perSecond = 99999.14;
        decimal perDay = seconds * (decimal)perSecond;              // I uint-->decimal 
        double nd2 = nationalDebt1 + (double)perDay; // decimal-->double 
        long nd3 = (long)nd2;                        // double-->long 
        float nd4 = (float)nd2;                      // double-->float 

    }

}

    


This entry was posted in Data Types. Bookmark the permalink.