Print Friendly and PDF
In C#, types are divided into two categories: • value types • Reference types. Value types directly contain their data, and reference types store references to their data. A third category of types called pointers, is available only in unsafe code. This pointer type will not be discussed in this document.
In C#, types are divided into two categories:
  • value types 
  • Reference types. 
Value types directly contain their data, and reference types store references to their data. The third category of types called pointers is available only in unsafe code. This pointer type will not be discussed in this document.

VALUE TYPES

In C#, a value type can be either a Struct or an enumeration. C# contains a set of predefined Struct types called the simple types. These simple types are identified through reserved words. All value types implicitly inherit from a class called object. Also, no type can derive from a value type. It is not possible for a value type to be null (null means “nothing” or “no value”). Assigning a variable of a value type creates a copy of the value. This is different from assigning a variable of a reference type, which copies the reference and not the object identified by the reference.

Example

Int,char,byte,bool,decimal ,double, enum , long ,sbyte,short ,struct,uint ,ulong ,ushort

REFERENCE TYPES

A reference type is one of the following: a class, an interface, an array, or a delegate. A reference type value is a reference to an instance of the type. null is compatible with all reference types and indicates the absence of an instance.

Class Types

A class defines a data structure containing data members (constants and fields), function members (methods, properties, events, indexers, operators, instance constructors, destructors and static constructors), and nested types.

The Object Type

The object class type is the ultimate base class of all other types. Every type in C# directly or indirectly derives from the object class type.

The String Type

The string type inherits directly from the class object.

Interface Types

An interface defines a contract. A class implementing an interface must adhere to its contract.

Array Types

An array is a data structure containing a number of variables that are accessed through indices. The variables contained in an array are called the elements of the array. They are all of the same types, and this type is called the element type of the array
zubairsaif

Zubair saif

A passionate writer who loves to write on new technology and programming

Post A Comment:

0 comments: