data type in c# language

Data Type In C# language -: C# programming language has two types. There are two kinds of types in C#:

  • Value types-: Variables of value types directly contain their data, whereas variables of reference types store references to their data, the latter being known as objects
  • Reference types.-: it is possible for two variables to reference the same object and, therefore, possible for operations on one variable to affect the object referenced by the other variable.

In the With value types, the variables each have their own copy of the data, and it is not possible for operations on one to affect the other (except in the case of ref and out parameter variables).

C#’s value types are further divided into simple types, enum types, struct types, and null-able types. C#’s reference types are further divided into class types, interface types, array types, and delegate types.

The following table provides an overview of C#’s type system.

data type C#

The eight integral types provide support for 8-bit, 16-bit, 32-bit, and 64-bit values in signed or unsigned form

C#’s bool type is used to represent Boolean values—values that are either true or false.

Character and string processing in C# uses Unicode encoding. The char type represents a UTF-16 code unit, and the string type represents a sequence of UTF-16 code units.

Boolean value c#

C# programs use type declarations to create new types. A type declaration specifies the name and the members of the new type.

Five of C#’s categories of types are user-definable:

  • class types
  • struct types
  • interface types
  • enum types
  •  delegate types.

A class type defines a data structure that contains data members (fields) and function members (methods, properties, and others). Class types support single inheritance and polymorphism, mechanisms whereby derived classes can extend and specialise base classes.

A struct type is similar to a class type in that it represents a structure with data members and function members. However, unlike classes, structs are value types and do not require heap allocation. Struct types do not support user-specified inheritance, and all struct types implicitly inherit from type object.

An interface type defines a contract as a named set of public function members. A class or struct that implements an interface must provide implementations of the interface’s function members. An interface may inherit from multiple base interfaces, and a class or struct may implement multiple interfaces.

A delegate type represents references to methods with a particular parameter list and return type. Delegates make it possible to treat methods as entities that can be assigned to variables and passed as parameters. Delegates are similar to the concept of function pointers found in some other languages, but unlike function pointers, delegates are object-oriented and type-safe.

Class, struct, interface, and delegate types all support generics, whereby they can be parameterized with other types.

An enum type is a distinct type with named constants. Every enum type has an underlying type, which must be one of the eight integral types. The set of values of an enum type is the same as the set of values of the underlying type.

 

Leave a Reply

Your email address will not be published. Required fields are marked *