17-12-2010 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>
1. C++ Style of type casting:
Syntax: <Todatatype> <Tovariable> = <(Todatatype)> <From variable>;
Eg: for C++ style of type casting:
Void main()
{
int i = 30;
Byte b = (Byte) i;
Console.WriteLine("b value is " +b);
Console.ReadLine();
}
Parasing: In parasing, we will use a predefined method called Parse().
Parse is a member method of every data type, predefined structure like below:
Struct int Struct Long
{ {
Parse() Parse()
{ {
} }
} }
Parse method will accept input as one argument that is also string only.
Using parse method we can convert from string data type to any other data type.
Syntax: <To datatype> <To Variable> = <To datatype>.Parse(<String>);
Eg: for parsing:
Void main()
{
Console.WriteLine("Enter your age: ");
int age = int.parse(Console.ReadLine());
Console.WriteLine("Your age is " +age);
Console.ReadLine();
}
Output: Enter your age
300
Your age is 300
Drawback: Using parsing we can convert from only string to any other data type that means parse method will accept input as only strings.
3. Converting: In converting we will use a predefined class called convert.
Convert class will have various data type conversion methods like below:
Class Convert
{
Toint16() Tosingle()
{ {
} }
Toint32() Todouble()
{ {
} }
Toint64() Tostring()
{ {
} }
}
Using converting we can convert from any data type to any other data type.
Syntax:
<To datatype> <To variable> = Convert.<Conversion method>(<from variable>);
Eg: for converting:
Void main()
{
Console.WriteLine("Enter first number");
int a = Convert.Toint32(Console.ReadLine());
Console.WriteLine("Enter second number");
int b = convert.Toint32(Console.ReadLine());
int c = a + b;
Console.WriteLine("C value is " +c);
Console.ReadLine();
}
Output: Enter first number
10
Enter second number
5
C value is 15
Boxing & Unboxing:
1. Boxing: Boxing is a process of converting from value type to reference type.
Eg: From int to object:
2. Un-Boxing: Unboxing is a process of converting from reference type to value type.
Eg: From object to int.
Synatx:
<To datatype> <Tovariable> = <(To datatype)> <from variable>
Ex: For boxing & unboxing:
Void main()
{
int i = 25;
object obj = (object) i; // Boxing
Console.WriteLine("Obj value is " +obj);
int j = (int) obj; // Unboxing
Console.WriteLine("j value is " +j);
Consloe.ReadLine();
}
Output: obj value is 25
j value is 25
OBJECT ORIENTED PROGRAMMING CONCEPTS (OOPS):
Syntax: To declare a class
<Access modifier> class <class name>
{
<Variables>;
<Properties>;
<Methods>;
<Constructors>;
<Destructors>;
<Events>;
<Indexers>;
}
1. C++ Style of type casting:
Syntax: <Todatatype> <Tovariable> = <(Todatatype)> <From variable>;
Eg: for C++ style of type casting:
Void main()
{
int i = 30;
Byte b = (Byte) i;
Console.WriteLine("b value is " +b);
Console.ReadLine();
}
Parasing: In parasing, we will use a predefined method called Parse().
Parse is a member method of every data type, predefined structure like below:
Struct int Struct Long
{ {
Parse() Parse()
{ {
} }
} }
Parse method will accept input as one argument that is also string only.
Using parse method we can convert from string data type to any other data type.
Syntax: <To datatype> <To Variable> = <To datatype>.Parse(<String>);
Eg: for parsing:
Void main()
{
Console.WriteLine("Enter your age: ");
int age = int.parse(Console.ReadLine());
Console.WriteLine("Your age is " +age);
Console.ReadLine();
}
Output: Enter your age
300
Your age is 300
Drawback: Using parsing we can convert from only string to any other data type that means parse method will accept input as only strings.
3. Converting: In converting we will use a predefined class called convert.
Convert class will have various data type conversion methods like below:
Class Convert
{
Toint16() Tosingle()
{ {
} }
Toint32() Todouble()
{ {
} }
Toint64() Tostring()
{ {
} }
}
Using converting we can convert from any data type to any other data type.
Syntax:
<To datatype> <To variable> = Convert.<Conversion method>(<from variable>);
Eg: for converting:
Void main()
{
Console.WriteLine("Enter first number");
int a = Convert.Toint32(Console.ReadLine());
Console.WriteLine("Enter second number");
int b = convert.Toint32(Console.ReadLine());
int c = a + b;
Console.WriteLine("C value is " +c);
Console.ReadLine();
}
Output: Enter first number
10
Enter second number
5
C value is 15
Boxing & Unboxing:
1. Boxing: Boxing is a process of converting from value type to reference type.
Eg: From int to object:
2. Un-Boxing: Unboxing is a process of converting from reference type to value type.
Eg: From object to int.
Synatx:
<To datatype> <Tovariable> = <(To datatype)> <from variable>
Ex: For boxing & unboxing:
Void main()
{
int i = 25;
object obj = (object) i; // Boxing
Console.WriteLine("Obj value is " +obj);
int j = (int) obj; // Unboxing
Console.WriteLine("j value is " +j);
Consloe.ReadLine();
}
Output: obj value is 25
j value is 25
OBJECT ORIENTED PROGRAMMING CONCEPTS (OOPS):
1. Class & Object1. Class & Object: Class is a collection of members, it can contain variables, properties, methods, constructors, destructors, events & indexers & So on..
2. Abstraction
3. Encapsulation
4. Inheritance
5. Polymorphism
Syntax: To declare a class
<Access modifier> class <class name>
{
<Variables>;
<Properties>;
<Methods>;
<Constructors>;
<Destructors>;
<Events>;
<Indexers>;
}