What are the data types available in C#

C# offers a variety of data types that allow developers to work with different kinds of data. Here are some of the commonly used data types in C#:

  • int - Represents a 32-bit signed integer.
  • float - Represents a single-precision floating point.
  • double - Represents a double-precision floating point.
  • char - Represents a single 16-bit Unicode character.
  • string - Represents a sequence of characters.
  • bool - Represents a Boolean value (true or false).
  • decimal - Represents a 128-bit precise decimal number, useful for financial calculations.
  • object - The base type from which all types, both value types and reference types, derive.

Example of Different Data Types in C#

int age = 30; float height = 5.9f; double weight = 70.5; char initial = 'J'; string name = "John Doe"; bool isEmployed = true; decimal salary = 75000.50m; Console.WriteLine($"Name: {name}, Age: {age}, Height: {height}, Weight: {weight}, Initial: {initial}, Employed: {isEmployed}, Salary: {salary}");

C# data types C# programming C# variables C# int C# string