By 22/07/2015 6 Comments

C# Integers

  • They contains whole number values (e.g.: 100, 200 etc).
  • It is used to store whole, signed and unsigned numeric values.
  • This data type mostly used in C # for mathematical calculations such as (+, – , *, /) etc.
  • In C# int data type is being mostly used in many cases.

Difference between signed and unsigned types:

  • Int = signed int, we can assign or store negative values as well as positive values to it.
  • uint = unsigned int, we cannot assign or store negative number values to it.
DATA TYPE WIDTH IN BITS RANGE
byte 8 0 To 55
sbyte 8 -128 To 127
short 16 –32,768 to 32,767
ushort 16 0 to 65,535
int 32 –2,147,483,648 to 2,147,483,647
uint 32 0 to 4,294,967,295
long 64 –9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
ulong 64 0 to 18,446,744,073,709,551,615

Example:

using System;
namespace csharpBasic
{
    // Start class definition / declaration.
    class Program
    {
        // Static main method void type declaration.
        static void Main(string[] args)
        {
            // Unsigned byte type varaible intialization.
            byte b = 55;

            // Print byte variable.
            Console.WriteLine("byte b: {0}", b);

            // Signed byte type varaible intialization.
            sbyte sb = -128;
            Console.WriteLine("sbyte sb: {0}", sb);

            // Signed short type variable initialization.
            short sh = -32768;
            Console.WriteLine("short sh: {0}", sh);

            // Unsigned short type variable initialization.
            ushort us = 0;
            Console.WriteLine("ushort us: {0}", us);

            // Signed int type variable initialization.
            int si = -2147483648;
            Console.WriteLine("int si: {0}", si);

            // Unsigned int type variable initialization.
            uint ui = 4294967295;
            Console.WriteLine("uint ui: {0}", ui);

            // Signed long type variable initialization.
            long l = -9223372036854775808;
            Console.WriteLine("long l: {0}", l);

            // Unsigned long type variable initialization.
            ulong ul = 223345;
            Console.WriteLine("ulong ul: {0}", ul);

            Console.ReadKey();

        } // End of main method definition. 
    } // End of class. 
}





Next Tutorial →


← Previous Tutorial


Posted in: C# Basics, C#.NET

Leave your valuable Comment

Have a natural attraction for women cosmetics and replica watches uk clothes, no
more than two for men the most attractive one, is to make their own driving experience, happy and can serve as the facade of the car, another is to highlight the taste edify sentiment rolex replica watch. The replica rolex is undoubtedly the most fashionable accessories, wear a suit to attend the activities, but also get a decent match on the replica watches .