What are the Variables and Variable Types in C sharp


"Variables" are simply storage locations for data in program. Programmer is able to place data into variable and retrieve their contents. The interpretation of the data in a variable is controlled through "Types".

The C# simple types consist of the Boolean, Integrals, Floating Point, Decimal and String. In integrals types includes sbyte, byte, short, int, uint, long, and char.

In “Floating Point" refers to the float and double types


The Boolean Type
Boolean types are declared using the keyword, bool. They have two values: true or false.
          bool state = true;
        bool noState = false;


Integral Types
They are whole numbers, either signed or unsigned. Integral types are well suited for those operations involving whole number calculations.


The Size and Range of C# Integral Types
Type
Size (in bits)
Range
sbyte
8
-128 to 127
byte
8
0 to 255
short
16
-32768 to 32767
ushort
16
0 to 65535
int
32
-2147483648 to 2147483647
uint
32
0 to 4294967295
long
64
-9223372036854775808 to 9223372036854775807
ulong
64
0 to 18446744073709551615





Floating Point and Decimal Types
In C# floating point type is either a float or double. Floating point types are used when you need to perform operations requiring fractional representations.

The Floating Point and Decimal Types with Size, precision, and Range
Type
Size (in bits)
precision
Range
float
32
7 digits
1.5 x 10-45 to 3.4 x 1038
double
64
15-16 digits
5.0 x 10-324 to 1.7 x 10308
decimal
128
28-29 decimal places
1.0 x 10-28 to 7.9 x 1028



The string Type
A string is a collection of characters. This type allows us to manipulate character data through methods and properties. It provides methods to concatenate, append, replace, search and split.


String has the following characteristics

  1. It is a reference type – string is not a value type. It is a reference type.
  2. It's immutable - You can never change the contents of a string. If you try to do, it just sets the value of string to a new string, which is a copy of the old string.
  3. It can contain nulls - In .NET, strings can contain null characters with no problems at all as far as the string methods themselves are concerned
  4. It overloads by the == operator - When the == operator is used to compare two strings, the Equals method is called




1 comments:

  1. Anyway, as you can tell, I've been very happy to read your instruction and I want them to do well so I can keep using them!Thanks for sharing.

    wow error
    134

    thanks

    ReplyDelete

Thank you very much