C# Data Types

Data Types in C#

In C#, a data type specifies what kind of data a variable can hold. Data types are important because they define the size and layout of the variable’s memory, the range of values that can be stored, and the set of operations that can be applied to the variable.

Basic Example of a variable with data type:

Commonly Used Data Types Example:

Data TypeWhat It HoldsExamplePrecision
intWhole numbers (no decimals)

int weight1 = 55;  // Valid: Assigning an integer value directly | int weight2 = 55.5;  // Invalid: Attempting to assign a decimal value to an integer

N/A (Integer)
floatIt only gives output with 7-digit numbers with a decimal point or less than 7 if the number of digits is 7 it will round the last number otherwise not

float Amount = 46.12345678910111213141516171819f; the output will be – 46.12346 | float Amount = 46.1234f; the output will be –  46.1234

7 digits
doubleIt only gives output with 15-digit numbers with a decimal point or less than 15

double Amount = 46.12345678910111213141516171819; the output will be –  46.1234567891011 | double Amount = 46.1234567891; the output will be –  46.1234567891

15 digits
decimalIt only gives output with 29-digit numbers with a decimal point or less than 29

decimal Amount = 46.12345678910111213141516171819m the output will be –  46.123456789101112131415161718 | decimal Amount = 46.12345678910111213141m the output will be –  46.12345678910111213141

28 digits
charA single character (like a letter)

char grade1 = ‘A’;  // Valid: Single character enclosed in single quotes | char grade2 = ‘A+’;  // Invalid: Attempting to assign more than one character

1 character
stringA sequence of characters (like words)

string name1 = “Emily”;  // Valid: String enclosed in double quotes | string name2 = Emily;  // Invalid: Missing double quotes for string literal

N/A (Depends on string length)
boolTrue or false values. It cannot take any other value beside true or false

bool isValid1 = true;  // Valid: Assigned the Boolean value ‘true’ | bool isValid2 = 23;  // Invalid: Attempting to assign an integer value

1bit (True/False)

Course Video

Course Video In English

Frequently Asked Questions

Still have a question?

Let's talk

C# data types define the kind of data a variable can store, such as integers, floating-point numbers, characters, or strings.

C# data types are categorized into value types (e.g., int, float), reference types (e.g., string, object), pointer types, and nullable types.

Choose a data type based on the size of the data and memory requirements. For example, use int for integer values and double for fractional values.

C# has two main categories of data types:

  1. Value Types: int, float, bool, char, etc.
  2. Reference Types: string, object, dynamic, etc.

Yes, Iqra Academy offers tutorials that explain C# data types with practical examples and clear explanations to help beginners understand easily.

Yes, You can learn C# data types for free in an online course at Iqra Academy, complete with examples, video tutorials, and lessons in Hindi for beginners.

Yes, Iqra Academy provides C# data type tutorials with video lessons in Hindi, making it easy for beginners to learn.

Beginners should focus on key data types like:

  • int for integers
  • float for decimals
  • bool for true/false
  • string for text
  • char for single characters

Data types in C# are foundational for .NET development, as they determine how data is stored, processed, and transferred within applications.

Yes, Iqra Academy offers a free online course on C# data types, covering concepts, examples, and practical lessons for beginners.

Learning C# data types is essential for understanding memory allocation, performing operations correctly, and building efficient .NET applications.

Here’s a quick list of C# data types:

Value Types: int, double, bool, char, etc.
 Reference Types: string, object, dynamic.