Floating-Point Types:
1)float: 32-bit single-precision floating point type
2)double: 64-bit double-precision floating point type
float myFloat = 20.5f;
Decimal Type:
1)decimal: 128-bit precise decimal values with 28-29 significant digits, suitable for financial and monetary calculations
decimal myDecimal = 100.5m;
Other Value Types:
1)char: 16-bit Unicode character
2)bool: Represents Boolean values, true or false
bool myBool = true;
char myChar = 'A';
Reference Types:
String Type:
1)string: Represents a sequence of Unicode characters
string myString = "Hello, World!";
Object Type:
1)object: The base type from which all other types derive
object myObject = myString;
Dynamic Type
1)dynamic: Type resolved at runtime, providing flexibility at the cost of some performance and type safety
dynamic myDynamic = 10; // dynamic type can change
Nullable Types
1)Nullable: Allows value types to be assigned null (e.g., int?, double?)
int? myNullableInt = null;
Arrays:
1)Array: Represents a fixed-size sequence of elements of the same type
int[] myArray = {1, 2, 3, 4, 5};
Enum Type:
1)enum: Represents a set of named constants
enum Day { Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday }
Day today = Day.Monday;
Struct Type:
1)struct: A value type that can encapsulate data and related functionality
struct Point
{
public int X;
public int Y;
}
Point p = new Point();
p.X = 10;
p.Y = 20;
Class Type:
1)class: A reference type that can encapsulate data and related functionality
class MyClass {
public int Number;
public void Display() {
Console.WriteLine(Number);
}
}
MyClass obj = new MyClass();
obj.Number = 5;
obj.Display();
Interface Type:
1)interface: Defines a contract that can be implemented by classes and structs
class MyClassWithInterface : IMyInterface
{
public void MyMethod()
{
Console.WriteLine("Interface Method");
}
}
IMyInterface myInterface = new MyClassWithInterface();
myInterface.MyMethod();
Delegate Type:
1)delegate: Represents a reference to a method
delegate void MyDelegate(string message);
MyDelegate del = (msg) => Console.WriteLine(msg);
del("Hello, Delegate!");
Top comments (0)