Thursday , December 14 2017
Home / Dot Net / C# / Lesson 4: DataTypes in C#

Lesson 4: DataTypes in C#

DataTypes in C#: 

C# is a strongly typed and rich language; therefore every variable in C# is associated with a Data type. Data types specify the type of values that can be stored in a variable.

C# provides all the data types that are available in Java, and adds support for unsigned numerals and a new 128-bit high-precision floating-point type.

All primitive data types in C# are objects in the System namespace. For each data type, a short name, or alias, is provided. For instance, int is the short name for System.Int32 and double is the short form of System.Double.

DataTypes are two types:

1.Built in datatypes

2.User defined datatypes

Built-In DataTypes

Short Name Default Value Type Width Range (bits)
byte 0 Unsigned integer 8 0 to 255
sbyte 0 Signed integer 8 -128 to 127
int 0 Signed integer 32 -2,147,483,648 to 2,147,483,647
uint 0 Unsigned integer 32 0 to 4294967295
short 0 Signed integer 16 -32,768 to 32,767
ushort 0 Unsigned integer 16 0 to 65535
long 0L Signed integer 64 -9223372036854775808 to 9223372036854775807
ulong 0 Unsigned integer 64 0 to 18446744073709551615
float 0.0F Single-precision floating point type 32 -3.402823e38 to 3.402823e38
double 0.0D Double-precision floating point type 64 -1.79769313486232e308 to 1.79769313486232e308
char ‘\0’ A single Unicode character 16 Unicode symbols used in text
bool False Logical Boolean type 8 True or false
string “” A sequence of characters
decimal 0.0M Precise fractional or integral type that can represent decimal numbers with 29 significant digits 128 ±1.0 × 10e−28 to ±7.9 × 10e28

Example:

Output:

Studyclues_C#_Datatypes

2.User Defined Datatypes:

The value types which are defined by the user is known as user-defined types. There are two user-defined types :

Structure : A structure is simply a composite data type consisting of a number of elements of other data types; it is almost same as classes but is used in context of relatively simple

Example:

OutPut:

Studyclues_C#_Struct Example

Enumerations : 

An enumeration provides a way for attaching names to numbers in a program, which in turn increases the readability of code; we use enum keyword in C# to declare an enumeration.

Output:

Studyclues_C#_Enumeration Example

Size of:

Sizeof, an operator, returns a size. This is the number of bytes a type (the argument) uses.

in other words To find the size of an arbitrary variable, x, at runtime we can use sizeof() method

Example:

Output:

4

Back To C# Complete Tutorials

Thanks for reading this article and if you like this please share with your Friends.

Print Friendly, PDF & Email

Give us your valuable feedback

comments

About Murali

Hello everyone I am Software Developer having 3+ years of Experience in Microsoft Technologies and Others.

My skills :- Asp.net, C#,Ado.net, SQL SERVER, web services, windows Service,Windows applications,HTML,CSS,
JavaScript,JQuery,AnjularJs

Check Also

studyclues_c_object

Lesson 8: Object In C#

c# object: A class and an object are different things. A class defines a type of …

%d bloggers like this: