Family of Integers : Integer Family « Data Type « C# / CSharp Tutorial






C# defines nine integer types:

  1. char,
  2. byte,
  3. sbyte,
  4. short,
  5. ushort,
  6. int,
  7. uint,
  8. long,
  9. ulong.

char type is used for representing characters

The integer structures are

  1. Byte
  2. SByte
  3. Int16
  4. UInt16
  5. Int32
  6. UInt32
  7. Int64
  8. UInt64

The integer structures also define the following const fields:

  1. MaxValue
  2. MinValue

Methods Supported by the Integer Structures

MethodMeaning
public int CompareTo(object v)Returns 0 if the values are equal. Returns a negative value if the invoking object has a lower value. Returns a positive value if the invoking object has a greater value.
public override bool Equals(object v)Returns true if equal.
public override int GetHashCode()Returns the hash code.
public TypeCode GetTypeCode()Returns the TypeCode enumeration value. For example, for Int32, the type code is TypeCode.Int32.
public static retType Parse(string str)Parses the string.
public static retType Parse(string str,IFormatProvider fmtpvdr)Parse string using the culture-specific information provided by fmtpvdr.
public static retType Parse(string str, NumberStyles styles)Parse string using the style information provided by styles.
public static retType Parse(string str, NumberStyles styles,IFormatProvider fmtpvdr)Parse string using the style information provided by styles and the culture-specific format information provided by fmtpvdr.
public override string ToString()Convert value to string.
public string ToString(string format)Convert value to string as specified by the format string.
public stringToString(IFormatProvider fmtpvdr)Returns the string representation of the value of the invoking object using the culture-specific information.
public stringToString(string format,IFormatProvider fmtpvdr)Returns the string representation of the value of the invoking object using the culture-specific information and the format.


All of the integer structures implement the following interfaces:

  1. IComparable,
  2. IConvertible, and
  3. IFormattable.








2.4.Integer Family
2.4.1.Family of Integers
2.4.2.Integer Types
2.4.3.Integer ranges
2.4.4.Use 'is' for int value type
2.4.5.A C# int is a shorthand for System.Int32, which inherits the following members from System.Object
2.4.6.Shifting an integer value