0% found this document useful (0 votes)
11 views1 page

C# Data Types Overview Cheat Sheet

This cheat sheet outlines the basic data types in C#, detailing their sizes, value ranges, declaration examples, and conversion methods. It includes types such as byte, int, float, and string, along with common conversion methods like Convert.ToInt32 and TryParse. The document serves as a quick reference for C# developers to understand and utilize these data types effectively.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views1 page

C# Data Types Overview Cheat Sheet

This cheat sheet outlines the basic data types in C#, detailing their sizes, value ranges, declaration examples, and conversion methods. It includes types such as byte, int, float, and string, along with common conversion methods like Convert.ToInt32 and TryParse. The document serves as a quick reference for C# developers to understand and utilize these data types effectively.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

C# Basic Data Types Cheat Sheet

This cheat sheet provides an overview of the most commonly used built-in C# data types, including
their sizes, value ranges, declaration, and conversion examples.

Type Size (Bytes) Range Example Declaration Conversion Example

byte 1 0 to 255 byte a = 100; int b = Convert.ToInt32(a);

sbyte 1 -128 to 127 sbyte x = -50; string s = [Link]();

short 2 -32,768 to 32,767 short num = 25000; int y = Convert.ToInt32(num);

ushort 2 0 to 65,535 ushort u = 60000; string str = [Link]();

int 4 -2,147,483,648 to 2,147,483,647 int age = 25; string s = [Link](age);

uint 4 0 to 4,294,967,295 uint count = 1000; long l = Convert.ToInt64(count);

long 8 -9.22e18 to 9.22e18 long distance = 123456789L; string s = [Link]();

ulong 8 0 to 1.84e19 ulong pop = 10000000000; double d = [Link](pop);

float 4 ±1.5e−45 to ±3.4e38 float price = 10.5f; double d = [Link](price);

double 8 ±5.0e−324 to ±1.7e308 double rate = 2.75; float f = [Link](rate);

decimal 16 ±1.0e−28 to ±7.9e28 decimal salary = 25000.75m; double d = [Link](salary);

char 2 Unicode (U+0000 to U+FFFF) char grade = 'A'; int code = Convert.ToInt32(grade);

bool 1 (logical) true or false bool active = true; string s = [Link](active);

string variable 0 to 2B characters string name = "John"; int len = [Link];

object variable Any type object data = 42; int num = Convert.ToInt32(data);

Common Conversion Methods


Method Purpose Example

Convert.ToInt32() Converts to integer int x = Convert.ToInt32("25");

[Link]() Converts to double double d = [Link]("2.5");

[Link]() Converts to string string s = [Link](10);

[Link]() Converts to bool bool b = [Link]("true");

ToString() Converts variable to string int x = 10; [Link]([Link]());

Parse() Converts string to numeric int y = [Link]("100");

TryParse() Safely converts string to numeric [Link]("100", out int n);

You might also like