Data types in c#
Datatype specifies the different sizes and values that can be assigned on the variable.
Data types can be classified into two main categories:
value types and reference type.
1 Value Types: Store the value in stack
Structs: These are user-defined data types that can contain data members and methods. They are value types because they directly store their data and are typically used for small, simple data structures.
Enums: Enums are enumeration data types used to define a set of named integral constants. They are also value types and are often used to represent a set of related named constants.
Following are value types
int 4bytes
char 2bytes
bool 1bit
float 4bytes
领英推荐
double 8bytes
long 8bytes
2? Reference Types: Store the value in heap
String: Strings are sequences of characters and are reference types because they are stored in the managed heap and accessed through references.
Arrays: Arrays are collections of elements of the same type that are stored in contiguous memory locations. They are reference types as well.
Objects: Objects are instances of classes, which are user-defined reference types that encapsulate data and behavior.
Class: Classes are blueprints for creating objects. They define the structure and behavior of objects.
Interface: Interfaces define a contract that classes can implement. They specify methods, properties, events, and indexers that implementing classes must provide.
Delegate: Delegates are reference types that hold references to methods, allowing for method invocation through the delegate object.