Value Types Data in ASP.Net C#

Variable that are based on value types directly contain a values. Assigning one value type variable to another copies the contained value. This differs from the assignment of reference type variables, which copies a reference to the object but not the object itself.

All value types are derived implicitly from the System.ValueType.

Unlike reference types, it is not possible to derive a new type from a value type. However, like reference types, structs can implement interfaces.

Unlike reference types, it is not possible for a value type to contain the null value. However, the nullable types feature does allow values types to be assigned to null.

The value types consist of two main categories:
  • Structs
  • Enumerations
Structs fall into these categories:
  • Numeric types
  • bool
  • User defined structs.
int myInt;

you cannot use it before you initialize it. You can initialize it using the following statement:

myInt = new int(); // Invoke default constructor for int type.

which is equivalent to:

myInt = 0; // Assign an initial value, 0 in this example.

You can, of course, have the declaration and the initialization in the same statement like this:

int myInt = new int();
Tags: , ,
Hot on Web:


About author