0% found this document useful (0 votes)
409 views

Datatypes in C#

The document discusses different data types in C#, including value types, reference types, and special types like object, dynamic, and string. It provides examples of boxing and unboxing between value and reference types. Key points covered include how value types store data directly while reference types store references, and how the object type serves as the base for all other types. Examples are given for declaring and using pointer, dynamic, and string types as well.

Uploaded by

Nayan Sawant
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
409 views

Datatypes in C#

The document discusses different data types in C#, including value types, reference types, and special types like object, dynamic, and string. It provides examples of boxing and unboxing between value and reference types. Key points covered include how value types store data directly while reference types store references, and how the object type serves as the base for all other types. Examples are given for declaring and using pointer, dynamic, and string types as well.

Uploaded by

Nayan Sawant
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 11

Miss.Nandita R. Pawar.

Willingdon college ,Sangli.


Class :-Tybsc
Data Types

Value Type Reference Type

Pre-Defined User- defined Pre-Defined User -defined

-int ,
-Double, -Structure -Class
-Enumeration -String
-Float -Array
-Object
-Decimal
Value type variables can be assigned a value directly.
The value types directly contain data.
Some examples are int, char, and float, which stores
number, alphabets, and floating point numbers,
respectively.
When you declare an int type, the system allocates
memory to store the value.
The reference type do not contain the actual data
stored in a variable, but they contain a reference to the
variables.
Using multiple variables, the reference types can refer
to a memory location.
If the data memory location is changed by one by one
of the variables, the other variable automatically reflects
this change in value.
Examples are: object, dynamic, and string .
The Object Type is the ultimate base class for all data
type in C# common Type System(CTS).
The object types can be assigned values of any other
types, value types, reference types, predefined or user-
defined types.
When a value type is converted to object type, it is
called boxing and on the other hand.
When an object type is converted to a value type, it is
called unboxing.
Class TestBoxing:{{
Class programe
{
public static void main(string [ ], args );
{
int i =123; //Boxing copies the value of I into object o.
object o = I;
i= 456;
System Console . Write line(“The value-type value={0}”,i);
System Console . Write line(“The object-type value”{0}”,o);
System Console . Read line();
}
}

Output:
The Value-type value = 456
The object-type value = 123
Class Unboxing:

{
public static void main(string[ ],args)
{
string s=“15”; // reference type
int i=“Boxing”; // value type
i=int parse(s); // unboxing
Console.WriteLine(“The value of s=“+s”);
Console.WriteLine(“The value of i=“+i”);
Console.ReadLine();
}
}

OUTPUT:

The Value of s=Boxing


The Value of i=15
 You can store any type of value in the dynamic data
type variable.
 Type checking for these types of variables takes
place at run-time.
 Syntax for declaring a dynamic type is:
dynamic <variable name>=value;
 For Example:
dynamic d = 20;
 Dynamic types are similar to object types except that
type checking for object type variables takes place at
compile time, whereas that for the dynamic type
variables takes place at run time.
The String Type allows you to assign any string
values to a variable.
It is derived from object type.
The value for a string type can be assigned using
string literals in two forms: quoted and
@quoted.
For Example,
A quoted string literal looks as follows;
String str= “Tutorial looks as follows;
A @quoted string literal looks as follows;
String str= @ “Tutorial Point”;
Pointer type variables store the memory address of
another type .
Pointer in C# have the same capabilites as the pointers
in C or C++.
Syntax :
type* identifier;For example,
Example :
Char* cptr;
int* iptr;

You might also like