In C#, a data type is a classification of types of data that determines the possible values for that type, the operations that can be performed on it, and how it can be used.
C# includes a number of built-in data types, which can be grouped into the following categories:
Value types: These data types store a value directly, and include types such as int, float, bool, and char.
Reference types: These data types store a reference to an object, and include types such as string, object, and arrays.
Pointer types: These data types store a memory address, and are used for low-level operations. Pointer types are generally not used in C# unless you are working with unsafe code.
Here is a list of some of the most commonly used data types in C#:
- bool: A boolean value (true or false).
- char: A single Unicode character.
- byte: An 8-bit unsigned integer.
- sbyte: An 8-bit signed integer.
- short: A 16-bit signed integer.
- ushort: A 16-bit unsigned integer.
- int: A 32-bit signed integer.
- uint: A 32-bit unsigned integer.
- long: A 64-bit signed integer.
- ulong: A 64-bit unsigned integer.
- float: A 32-bit single-precision floating-point value.
- double: A 64-bit double-precision floating-point value.
- decimal: A 128-bit precise decimal value.
- string: A string of Unicode characters.
- object: A reference type that can hold any value.
In addition to these built-in data types, you can also create your own custom data types using classes, structures, and enumerations.
For example, you could create a Point structure to represent a point in two-dimensional space, like this:
struct Point
{
public int X;
public int Y;
}You can then create variables of type Point and set their values like this:
Point p1;
p1.X = 10;
p1.Y = 20;
Point p2 = new Point { X = 30, Y = 40 };
Comments
Post a Comment