Professional Documents
Culture Documents
NET
EXAMPLE
VB:
Dim sal As Integer
msgbox(sal)
Output: zero
C#
Int sal
Sal=10
MessageBox.Show(sal)
Output : Error
Program
Type casting is the concept of converting one Data Type into another
datatype.
int i=10;
byte b= (byte) i ;
Note:
Draw back of C++ TypeCasting. There is possibility for lossing
original data
Working With Parsing
As per DotNet all predefined data types are predefined structures.
Structures is a collection of methods (function)
Parse()
Max value
Data Type
ToString()
Min value
MessageBox.Show(int.MinValue.ToString());
MessageBox.Show(int.MaxValue.ToString());
Ex 2: On Parsing:
}
Working with Converting:
Converting can be used convert from any datatype into any other
datatype.
Methods of Convert Class:
Convert. ToChar(value)
Convert.ToByte(value)
Convert.ToBoolean(value)
Convert.ToString(value)
Convert.ToDateTime(value)
Convert.Toint16(value)
Convert.Toint32(value)
Convert.Toint64(value)
UNBOXING
LOOPS:
Loops are execute a set of statement repeatedly based on a
condition.
LOOPS
For While
Do_While
for(intialization; condition; ++/--;) While(condition) do
{
{
---------;
------;
FOR LOOP (A Program to print from A to Z)
Ex1:
for (int i = 65; i <= 90; i++)
{
char c = Convert.ToChar(i);
MessageBox.Show(c.ToString());
}
Ex2:
int x = 10;
for (int i = 1; i <= 10; i++)
{
TextBox t = new TextBox();
t.Location = new Point(100, x);
this.Controls.Add(t);
x = x + 30;
FOR EACH
Suntax
foreach(object in collection)
{
------;
}
Note:
Collection is a group of similar type of objects.
Ex:
place n textboxes and buttons on the form, when clicked on a
button change all textbox backcolor to green.
10 20 30 40 50
x[0] x[1]- - - -
Subscription Index
Operator
Array says same name with different Index no
- Always index start from zero.
- Arrays are belongs to reference type.
- As per DotNet array are instance of the predefined class
called as System.Array
- C# support three types of Array.
1. One Dimensional Array.
2 Two Dimensional Array.
3. Jagged Array.
Working With One Dimentional Array:
Syntax:
int[] x = new int[size];
Ex:
int[] x = new int[5];
Above statements creates five elements from x[0],x[1],x[2],- - -
x[4];
Arrays holds default value
Note:
While initializing array size is not recommended to specifiy
Button Click Event:
int[] x = new int[3] ;
MessageBox.Show(x.Length.ToString());
for (int i = 0; i < x.Length ; i++)
{
MessageBox.Show(x[i].ToString());
}
Note:
Integral default value is Zero.
Floating Default Value is Zero.
Bool default value is false.
Char default value is Null.
DateTime default value is -1/1/0001 12:00:00AM
Ex2:( A program to display the spelling of a given number(1 to
999)
Form Design
TextBox 1
TextBox 2
Button 1
Code For Button1_Click()
{
String[] ones = new string[] { "one", "Two", "Three",
"Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten",
"Elevn", "Twelve", "Thirteen", "Fourteen", "Fifteen",
"Sixteen", "Seventeen", "Eighteen", "Nineteen" };
}
Working With Multi_D Arrays:
x 0 1 2
0 Size : 3x3
Syntax to declar JA
int[ ] [ ] x = new int[rows] [ ];
x[0] = new [ ] {1,2,3,4};
x[1] = new [ ] {5,6,7};
x[2] = new [ ] {8,9};
Example For Jagged Array
{
int[][] x = new int[3][];
x[0] = new int[] { 1, 2, 3, 4 };
x[1] = new int[] { 5, 6, 7 };
x[2] = new int[] { 8, 9 };
string s = "";
for (int i = 0; i < x.GetLength(0); i++)
{
for (int j = 0; j < x[i].Length; j++)
{
s = s + " " + x[i][j].ToString();
}
s = s + "\n";
}
MessageBox.Show(s);
ENUMARATOR(ENUM):
Enum is a keyword.
Enum is a collection of integer constant.
Float values are not allowed in Enum.
By using integer constant can be maintain easily.
SYNTAX:
Enum <name>
{
value 1;
value 2;
value 3;
:
:
Value n
}
Enum must be declare in general Declaration Area.
int i, j, k;
i = (int)GPT.ne;
j = (int)GPT.rel;
k = (int)GPT.fr;
MessageBox.Show(i.ToString() + " " + j.ToString() + " " +
k.ToString());
}
}
}
1. Main() PROBLEM:
{ (No boundaries for
Datatype
int sal = 400000; practically)
printf(“%d”,sal);
}
2. Main( ) PROBLEM:
{ (No proper machanism
for
int I = 500 * 500/500; calculation)
printf(“%d”,i);
}
Abstraction:
Providing full information about an entity
Polymorphism:
Writing more then one function .Polymorphism is a concept of
providing many functionality with single name.
Inheritance:
It is a concept of deriving the features from one class into another
class.
What is a Class?
General:
Class is a logical representation of a physical Entity.
DotNet:
Class is a collection of fields, properties, methods and
event.
Object can access public data and object can not access private
data, it is called encapsulation.
Example:
Code for GD:
Class test
{
Private int i,j;
public void read(int x,int y)
{
i=x;
j=y;
}
public void prin()
{
int k=i+j;
MessageBox.Show(k.ToString());
}
Code for button click:
private void button1_Click(object sender, EventArgs e)
{
test t1 = new test();
test t2 = new test();
t1.read(5, 6);
t2 = t1; t1.prin(); t2.prin(); }
Object is also called instance variable
For every object ,a separate set of instance variable will be
created. And a variable is under control of object , then it is called
object variable.
One object can be assigned to another object provided both must
be same type.
Example
Example:
class test
{
public void swap(int x, ref int y)
{
int t = x;
x = y;
y = t;
}
}
private void button1_Click(object sender, EventArgs e)
{
int a = 10, b = 20;
test t = new test();
t.swap(a, ref b);
MessageBox.Show(a.ToString() + " " + b.ToString());
}
Pass By Out:
Out is a keyword .
Out keyword must be used along with actual and formal args.
Out is 99% same as ref.
Out = ref – initialization.
Summary:
Call by value : value will be passed not address.
Call by reference : Address and value will be passed.
Call by out : only address will be passed.
Example:
class test
{
public void add(int x, int y, out int z)
{
z = x + y;
}
}
Note:
One function can have any number of out parameters as well as
ref parameters.