Order Now

Built-In Data Types & Variables

shape image

Built-In Data Types & Variables

Built-In Data Types & Variables


What is Data?

Data is a collection of information about any object or subject. Don't understand? ok, let's explain. You have your name, age, address, occupation, etc. This name, age, address, and occupation is data of you. 

If you think of a school. The school has some buildings, teachers, students, etc. these also data of this school.

From a computer perspective, Data is a collection of information that can be processed by a computer. It can be any type of information, such as numbers, text, images, or sounds. Data is often organized and structured in a specific way to make it easier to use and analyze.

What are the data types and variables?

Data Type & Variable | zakirdev

A data type in C# is a classification of types of data that determine the possible values and operations that can be performed on that data. Data types are used to represent different types of information in a program. For example, you might use an integer data type to represent a person's age, a string data type to represent their name, and a Boolean data type to represent whether they are a student or not.

A variable is a named location in a computer's memory where a value can be stored. In C#, variables have a data type and a name. The value of a variable can be changed during the execution of a program.

Here's an example of how data types and variables might be used in a real-world scenario:

Imagine you are building a program to track student enrollment at a school. You might use variables to store information about each student, such as their name, age, and whether they are currently enrolled. Here's how you might declare some variables to represent this information:
string name;
int age;
bool isEnrolled;
You could then use these variables to store information about individual students:

name = "Zakir";
age = 29;
isEnrolled = true;
In this example, the name is a string variable that holds the value "Zakir", age is an integer variable that holds the value 29, and isEnrolled is a Boolean variable that holds the value true. You can use these variables to store and manipulate information about students in your program.

Declaration & Initialization
Figure: Declaration & Initialization


C# is a programming language that has a number of built-in data types. Here is a brief overview of some of the most commonly used data types in C#, along with examples of how they might be used:

  1. byte: A byte is an 8-bit integer value that can hold a value between 0 and 255. For example:
  2. byte b = 100;

  3. short: A short is a 16-bit integer value that can hold a value between -32768 and 32767. For example:
  4. short s = -5000;

  5. int: An int is a 32-bit integer value that can hold a value between -2147483648 and 2147483647. For example:
  6. int i = 10000;

  7. float: A float is a single-precision, 32-bit floating point value. For example:
  8. float f = 3.14f;

  9. double: A double is a double-precision, 64-bit floating point value. For example:
  10. double d = 3.14159;

  11. decimal: A decimal is a high-precision, 128-bit floating point value. For example:
  12. decimal dec = 3.14159265358979323846m;

  13. long: A long is a 64-bit integer value that can hold a value between -9223372036854775808 and 9223372036854775807. For example:
  14. long l = 1000000000;

  15. char: A char is a single Unicode character, enclosed in single quotation marks. For example:
  16. char c = 'A';

  17. string: A string is a sequence of characters, enclosed in double quotation marks. For example:
  18. string str = "Hello, world!";

  19. bool: A bool is a true or false value. For example:
  20. bool b = true;

  21. DateTime: A DateTime value represents a specific date and time. For example:
  22. DateTime dt = DateTime.Now;

  23. var: The var keyword allows you to declare a variable without specifying its data type. The data type will be inferred from the value assigned to the variable. For example:
  24. var x = 10;  // x is an int
    var y = "Hello";  // y is a string

  25. dynamic: The dynamic keyword allows you to declare a variable whose data type is not known at compile time. The data type will be determined at runtime. For example:
  26. dynamic x = 10;  // x is an int
    x = "Hello";  // x is now a string

Here is a list of all the data types in C#, along with their sizes and ranges:


Data Type Size (in bits) Range
bool 1 true or false
byte 8 0 to 255
sbyte 8 -128 to 127
short 16 -32768 to 32767
ushort 16 0 to 65535
int 32 -2147483648 to 2147483647
uint 32 0 to 4294967295
long 64 -9223372036854775808 to 9223372036854775807
ulong 64 0 to 18446744073709551615
char 16 A Unicode character
float 32 Approximately -3.4 x 10^38 to 3.4 x 10^38
double 64 Approximately -7.9 x 10^28 to 7.9 x 10^28 with 28-29 significant digits
object 32 or 64 A reference to an instance of a class or any value type
string A sequence of Unicode characters

Post a Comment

© Copyright 2023 ZakirDev

Order Form

I will contact you on WhatsApp.

Order now