Convert various data types to integer 64 : Convert « Data Types « C# / C Sharp






Convert various data types to integer 64

   

using System;

class Sample 
{
    public static void Main() 
    {
        bool    xBool = false;
        short   xShort = 1;
        int     xInt   = 2;
        long    xLong  = 3;
        float   xSingle = 4.0f;
        double  xDouble = 5.0;
        decimal xDecimal = 6.0m;
        string  xString = "7";
        char    xChar   = '8'; 
        byte    xByte  =  9;
    
        ushort  xUshort = 120;   
        uint    xUint =   121;
        ulong   xUlong =  122;
        sbyte   xSbyte  = 123;
    
        Console.WriteLine("Boolean:  {0}", Convert.ToInt64(xBool));
        Console.WriteLine("Int16:    {0}", Convert.ToInt64(xShort));
        Console.WriteLine("Int32:    {0}", Convert.ToInt64(xInt));
        Console.WriteLine("Int64:    {0}", Convert.ToInt64(xLong));
        Console.WriteLine("Single:   {0}", Convert.ToInt64(xSingle));
        Console.WriteLine("Double:   {0}", Convert.ToInt64(xDouble));
        Console.WriteLine("Decimal:  {0}", Convert.ToInt64(xDecimal));
        Console.WriteLine("String:   {0}", Convert.ToInt64(xString));
        Console.WriteLine("Char:     {0}", Convert.ToInt64(xChar));
        Console.WriteLine("Byte:     {0}", Convert.ToInt64(xByte));
        Console.WriteLine("UInt16:   {0}", Convert.ToInt64(xUshort));
        Console.WriteLine("UInt32:   {0}", Convert.ToInt64(xUint));
        Console.WriteLine("UInt64:   {0}", Convert.ToInt64(xUlong));
        Console.WriteLine("SByte:    {0}", Convert.ToInt64(xSbyte));
    }
}

   
    
    
  








Related examples in the same category

1.Convert string to int
2.Hidden among the To(integral-type) methods are overloads that parse numbers in another base:
3.The source and target types must be one of the "base" types. ChangeType also accepts an optional IFormatProvider argument. Here's an example:
4.Convert string to byte array with for loop
5.Convert byte array to string
6.Convert a decimal to the binary format
7.Convert.ToString Converts the value of a 32-bit signed integer to its equivalent string representation in a specified base.
8.Convert double to bool
9.Convert double to string
10.Convert console input to double
11.Converts int to string in a specified base.
12.Convert double to int
13.Convert double to bool and string
14.Convert string to char
15.Convert what you read from console into int
16.Returns an object of the specified type and whose value is equivalent to the specified object.
17.Convert.ChangeType Method (Object, TypeCode, IFormatProvider)
18.Converts a Unicode character array to an 8-bit unsigned integer array.
19.Convert.ToBase64CharArray() and Convert.FromBase64CharArray
20.Converts byte to Boolean
21.Converts decimal to Boolean value.
22.Converts double to Boolean value.
23.Converts short to Boolean value.
24.Converts int to Boolean value.
25.Converts long to Boolean value.
26.Converts string to Boolean
27.Converts Boolean value to byte.
28.Converts Unicode character to byte
29.Converts decimal number to byte
30.Converts double-precision floating-point number to byte
31.Convert string to bool with exception catch
32.Converts a string of length 4 to a 32-bit unsigned integer.
33.Converts a 32-bit unsigned integer to a string of length 4.
34.Conversion between C# string and packed string representation.
35.Convert object value to double or int