Before discussing C# Data Types, you should know the word datatype. So what is a data type? It is the type of data that a variable can store in the form of value. It can be of any kind, i.e., numerical data, textual data, character data, etc. I hope you got it. If you still have any queries related to C# Data Types, comment below. Now let’s discuss datatypes in C#.
C# Data Types Description
There are several C# Data Types look below:
Data type | Size of Datatype | Description of data type |
---|---|---|
int | 4 bytes | Stores whole numbers, without decimals / positive or negative |
float | 4 bytes | Stores fractional numbers, containing one or more decimals. Sufficient for storing 6-7 decimal digits |
double | 8 bytes | Stores fractional numbers, containing one or more decimals. Sufficient for storing 15 decimal digits |
char | 2 bytes | Stores a single character/letter/number, or ASCII values and it is surrounded by single comma like ‘a’ |
bool | 1 bit | Stores true or false values or on or off like |
string | 2 bytes per character | Stores a sequence of characters(i.e text), surrounded by double quotes(“”) |
long | 8 bytes | Stores whole numbers from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 |
Declaring Variable with C# Data Types with output
using System; namespace Codelikechamp { class Program { static void Main(string[] args) { int Num = 5; // integer (whole number) double DoubleNum = 5.99D; // floating point number char Letter = 'D'; // character bool Bool = true; // boolean string Text = "Hello"; // string Console.WriteLine(Num); Console.WriteLine(DoubleNum); Console.WriteLine(Letter); Console.WriteLine(Bool); Console.WriteLine(Text); } } }
Output of C# Data Types
5 5.99 D true Hello
Learn more about C#
Link: https://Codelikechamp.com
Medium Link: Follow me on Medium
Linkedin Link: Follow me on Linkedin