Вы находитесь на странице: 1из 105

Karthikeya

hanu.andru@yahoo.com

9052044478

TYPES OF NETWORK:
LAN: - The network limited to single organization located at a single place is known
as LAN...
Ex: office n/w, n/w with in a bank
MAN: - The network limited to single city and its sub urban places is known as
MAN
Ex: city cable n/w
WAN: - The network which has no limit in the universe is known as WAN
Ex: internet
EAN: - The network limited to single organization or group of organization located at
various places is known as EAN
We have 2 types of EAN..
1. intranet
2. extranet
INTRANET: - The network which is located to single organization located at various
places is known as intranet
Ex: banking n/w
If we have account in any bank we can perform transactions from any of its
branches
EXTRANET: - The n/w limited to group of organization located at various places is
known as extranet
Ex: ATM
Group of banks are becoming a group and they providing services
TYPES OF N/W COMPUTING:
If the type of n/w is lan, man, wan or ean we use following types of n/w
computing
CENTERLISED COMPUTING:
In this method client is connected to server. Clients are called as dumb terminals
because client would not contain any resources like
1. processor
2. ram
3. hard disk
4. Operating sys etc..
Total processing would be taken place at server only. Every command from client
would be transferred to sever and the server executes that command and returns
result back to client

Karthikeya

hanu.andru@yahoo.com

9052044478

DIS ADVANTAGES:
When number of clients increases burden on sever will be increased. n/w gets slow
down which reduces performance
CLIENT SERVER COMPUTING:
In this method all clients are connected to server. Clients are called intelligent or
smart terminals because client contains all the resources like cpu, ram, os and hard
disk etc. processing is getting done at client side only. Server is the storage medium
for the data
ADVANTAGES:
When no of clients increase no burden on the server. n/w doesnt slow down.
DISTRIBUTED COMPUTING:
In this method all clients are connected in an n/w. the data will be processed or shared
from any kind of device even it is other than the computer. Efficiency of this
computing is more
WHY .NET..?
.NET is a powerful tool used to build distributed computing application. .NET stands
for NETWORKING ENTERPRISE TOOL
1. OS
2. PACKAGES
3. APPLICATIONS(BANKING AND PAYROLL)
4. DATABASE
5. SERVER TECHNOLOGIES(BIG TALK, SHARE POINT)
6. ERP(ENERPRISE RESOURSE PACKAGE(SAP, CRM))
7. TESTING TOOLS (WIN RUNNER, LOADER AND QTP)
8. PROGRAMING LANGUAGES
.NET is a frame work tool which supports 41 programming languages
In this 41 there are 9 .NET pls
1. C#
2. C++
3. F#
4. J#
5. JSCRIPT
6. IRON PYTHON
7. IRON RUBY
8. VB
9. WNDOWS POWER SHELL

Karthikeya

hanu.andru@yahoo.com

9052044478

Asp.net is not a pl. it is a web technology. Its code can be written used C#, VB and J#

JAVA
purely object oriented pl
doesnt support operator over
loading
doesnt support multiple
inheritance
doesnt support pointers
provides GUI applications
supports general data types
plat form independent
doesnt provide language
interoperability

C#
purely object oriented pl
supports operator over loading
supports multiple inheritance
used interfaces
supports pointers used unsafe
key word
provides GUI applications
supports general data types
not a plat form independent
provides language
interoperability

CONSOLE APPLICATION:
By default VS.net creates a separate folder for each application. All the related
files are stored in this folder...
Any application in .NET is treated as a solution...
A solution will have default extension of .sln...
With given name of application a Namespace will created
A single Namespace can contain any number of classes
STRUCTURE OF A C#.NET PROGRAM:
Used system // List of Built in Namespaces required including in program
.. // It is similar to # include <stdio.h> in C, C++
..
Namespace Anyname of Namespace
{
Class classname
{
Static void Main (string [ ] args)
{
Statement
.
.
}
}
}
Every statement in C#.net ends with a terminator (;)
C#.net has case sensitive programming language

Karthikeya

hanu.andru@yahoo.com

FIRST PROGRAM:
Namespace CABasics
{
Class First
{
Static void Main (string [ ] args)
{
Console.WriteLine (Welcome);
Console.ReadLine ();
}
}
}
WRITING THE C#.NET CODE IN NOTEPAD:
In Notepad write the following code
Used system;
Used system.collection.generics;
Used system. Text;
Namespace CABasics
{
Class First
{
Static void Main (string [ ] args)
{
Console.WriteLine (Welcome);
Console.ReadLine ();
}
}
}

Then save the file with the name.cs


Then open Visual Studio command prompt
Type CSC filename.cs
Then type filename
Then press Enter

PATH OF C# .NET COMPILER:


C:\windows\microsoft.net\framework\version folder
CONSOLE CLASS:

9052044478

Karthikeya

hanu.andru@yahoo.com

9052044478

This class contains various properties and methods required to work with
input and output streams
METHODS:
1.
2.
3.
4.
5.

Clear();
Write(message);
WriteLine(message);
Read();
ReadLine();

CLEAR ():
This method is used to clear the contents of the screen
It is similar to clrscr () in C or C++
WRITE ():
This method is used to display some method on the screen
After displaying the message. The cursor remains in the same line
Console. Write (welcome);
O/p: welcome_ // cursor blinks after welcome
WRITELINE (message):
This method also used to display some methods on the screen
After displaying the message. The cursor will move to next line
Console.WriteLine (welcome);
O/p: welcome
_ // cursor blinks in new line
READ ():
This method is used to read a single character from the screen or input
stream
This method reads ASCII value of the character
READLINE ():
This method is also used to read the characters from the screen or from the
input screen
This method reads group of characters in the form of string
COMMENTS IN C#.NET:

Karthikeya

hanu.andru@yahoo.com

9052044478

//
Single line comment
/* .text. */ Multi line comment
* Write a program to find addition of two numbers..?
Namespace CABasics
{
Class Addition
{
Static void Main (string [ ] args)
{
int a, b;
a=10; b=20;
int c=a+b;
Console.WriteLine (Value of a is..+a);
Console.WriteLine (Value of b is..+b);
Console.WriteLine (Sum of a and b is..+c);
Console.ReadLine ();
}
}
}
NOTE:
Other way to print the value of C
Console.WriteLine (Sum is :{ 0}.c);
Similarly
Console.WriteLIne (Values of a and b is..{0}, {1}, a,b);
{0}, {1} are similar to %d or %f in C Language
READ () Vs READLINE ():
Read ()

ReadLine ()

1. Reads single/next character from the


screen/input stream
2. Reads maximum of 1 character
only
3. Reads ASCII value of the
character
4. Return type is Integer

1. Reads group of characters from the


screen/input stream
2. Reads maximum of 255 characters
3. Reads string value of the
characters
4. Return type is string

Karthikeya

hanu.andru@yahoo.com

9052044478

EXAMPLE FOR READLINE ():


Namespace CABasics
{
Class Addition
{
Static void Main (string [ ] args)
{
String Name; int age;
Console.WriteLine (Enter your Name and age...);
Name = Console.ReadLine ();
Age= Convert. To int32 (Console.ReadLine ());
Console. Clear ();
Console.WriteLine (your Name is...+Name);
Console.WriteLine (your age is...+age);
Console.ReadLine ();
}
}
}
EXAMPLE FOR READ ():
Namespace CABasics
{
Class clsExamples
{
Static void Main (string [ ] args)
{
int x;
Console.WriteLine (Enter any character...);
x = Console. Read ()
Console. Clear ();
Console.WriteLine (Entered value is... + x);
Console. Read ();
}
}
}
NOTE: Instead of

age = Convert. To int32 (Console.ReadLine ()); we can use


age = int. Parse (Console.ReadLine ());

PROGRAMING CONSTRUCTS:
The methods we use to write a program are called programming constructs

Karthikeya

hanu.andru@yahoo.com

9052044478

Any programming language will have three types of programming


constructs
1. Sequential
2. Selection
3. Iteration
* SEQUENTIAL:
In this method all the statements are executed one by one with out skipping
any statement
* SELECTION:
In this method compiler will execute only few statements and some set of
statements are ignored based on the given condition. There are four types of
selection statements
1. Simple If
2. If else
3. Nested If
4. Switch
* SIMPLE IF:
if (condition)
{
Statements
.
.
}
In this method, if the given condition is true the statements of if-block are
executed
Otherwise the statements of if-block are ignored
* IF ELSE:
if (condition)
{
Statements
.
.
}
else
{
Statements

Karthikeya

hanu.andru@yahoo.com

9052044478

.
.
}
In this method if the given condition is true if-block statements are executed...
If the given condition is false the else-block statements are executed
* NESTED IF:
In this method one or more if-conditions are included with in if-block or with
in else-block
if (condition)
{
Statements
.
.
}
else if
{
Statements
.
.
}
.
.
.
else
{
Statements
.
.
}
Example for Simple-If
Namespace CAselection
{
Class simpleif
{
Static void Main ()
{
int Empid;
Double basic, da=0, hra=0, gross;
String Ename;
Console. WriteLine (Enter Employee details...);

Karthikeya

hanu.andru@yahoo.com

9052044478

Empid=Covert. To int32 (Console.ReadLine ());


Basic=Covert. To Double (Console.ReadLine ());
If (Basic>5000)
{
da=0.4*Basic;
hra=0.2*Basic;
}
gross=Basic+da+hra;
Console. Clear ();
Console.WriteLine (Employee Id is...+Empid);
Console.WriteLine (Employee Name is...+Ename);
Console.WriteLine (Gross salary is...+Gross);
Console.ReadLine ();
}
}
}
NOTE:
Da and Hra should be initialized with any value
There is no guarantee that if block always runs
Hence it may be rise compile time error
Example for else-if
* Accept Employee details from user (Empid, Ename and Basic) then calculate Da,
Hra as given below
condition on salary
Da
Hra
Basic >= 5000
40%
20%
Basic <= 5000
30%
10%
Namespace CAselection
{
Class simpleif
{
Static void Main ()
{
int Empid;
Double basic, da=0, hra=0, gross;
String Ename;
Console. WriteLine (Enter Employee details...);
Empid=Covert. To int32 (Console.ReadLine ());
Basic=Covert. To Double (Console.ReadLine ());
If (Basic>=5000)
{
da=0.4*Basic;

10

Karthikeya

hanu.andru@yahoo.com

9052044478

hra=0.2*Basic;
}
else
{
da=0.3*Basic;
hra=0.1*Basic;
}
gross=Basic+da+hra;
Console. Clear ();
Console.WriteLine (Employee Id is...+Empid);
Console.WriteLine (Employee Name is...+Ename);
Console.WriteLine (Gross salary is...+Gross);
Console.ReadLine ();
}
}
}
Example on Nested-if
* WAP which accept age of a person and display message as given below
Age
Message
0 -5
you are a kid
6 - 12
you are a child
13 - 19
you are a Teenager
20 - 35
you are a Youngster
35 - 50
you are in Middle age
>50
you are in Old age
Namespace CABasics
{
Class Nestedif
{
Static void Main (string [ ] args)
{
int age;
Console.WriteLine (Enter your age...);
Age= Convert. To int32 (Console.ReadLine ());
If (age<=5)
{
Console.WriteLine (you are a kid...);
}
else If (age<=12)
{
Console.WriteLine (you are a child...);
}
else If (age<=19)
{

11

Karthikeya

hanu.andru@yahoo.com

9052044478

Console.WriteLine (you are a Teenager...);


}
else If (age<=35)
{
Console.WriteLine (you are a youngster...);
}
else If (age<=50)
{
Console.WriteLine (you are in Middle age...);
}
else
{
Console.WriteLine (you are in old age...);
}
Console.ReadLine ();
}
}
}
SWITCH CONDITION:
Switch (condition)
{
case exp1:
{
Statements
..
..
break;
}
case exp2:
{
Statements
..
..
break;
}
..
..
..
default:
{
Statements
..
..
break;

12

Karthikeya

hanu.andru@yahoo.com

9052044478

}
}
We can also write switch case as shown as below
Switch (condition)
{

case exp1:
case exp2:
case exp3:
case exp4:

{
Statements
..
..
break;
}
case exp5:
{
Statements
..
..
break;
}
..
..
..
default:
{
Statements
..
..
break;
}

these will work as or (||) operator

}
Example on switch
* WAP to find given character is vowel or consonant
Namespace CABasics
{
Class switch

13

Karthikeya

hanu.andru@yahoo.com

9052044478

{
Static void Main (string [ ] args)
{
String alpha;
Console.WriteLine (Enter any character...);
alpha = Console.ReadLine ();
Console. Clear ();
Switch (alpha)
{
case a:
case e:
case i:
case o:
case u:
{
Console.WriteLine (vowel);
}
default:
{
Console.WriteLine (consonant);
}
}
Console.ReadLine ();
}
}
}
ITERATIONS:
Iterations are used to execute group of statements repeatedly for required
number of times. In c# they are 4 types
1.
2.
3.
4.

for loop
while loop
do-while loop
for-each loop

FOR LOOP:
For (variable = start value; condition; variable increment/decrement)
{
Statements
..
..
}
WHILE LOOP:

14

Karthikeya

hanu.andru@yahoo.com

9052044478

While (condition)
{
Statements
..
..
increment/decrement of variable;
}
DO WHILE LOOP:
Do
{
Statements
..
..
increment/decrement of variable;
} while (condition)
Example on for loop
* WAP to find the factors of given numbers
Namespace CABasics
{
Class forloop
{
Static void Main (string [ ] args)
{
int num;
Console.WriteLine (Enter any number...);
Num = Convert. To int32 (Console.ReadLine ());
Console. Clear ();
For (int i=1; i<=num; i++)
{
if (num%i == 0)
Console.Write (i+\t);
}
Console.ReadLine ();
}
}
}
Example on while-loop
* WAP to find Reverse number of given number

15

Karthikeya

hanu.andru@yahoo.com

9052044478

Namespace CABasics
{
Class forloop
{
Static void Main (string [ ] args)
{
int num, Rnum=0;
Console.WriteLine (Enter any number...);
Num = Convert. To int32 (Console.ReadLine ());
Console. Clear ();
While (num>0)
{
Rnum = (Rnum*10) + (num%10);
Num = num/10;
}
Console.WriteLine (Reverse number is + Rnum);
Console.ReadLine ();
}
}
}
KEY WORDS IN C#:
C#.NET contains 2 types of keywords
1. Reserved keywords
2. Contextual keywords
RESERVED Vs CONTEXTUAL:
RESERVED

CONTEXTUAL

1. These are syntactical words


used to write code like if, for
etc
2. Total 77 are present in C#.NET
3. Reserved cant be used as a
variable directly. To declare
them as a variable then use @
symbol before
Ex:
int if; // not allowed
Int @if; // allowed

1. These have special meaning to


the compiler
2. total 6 contextual keywords are
present in C#.NET
3. Contextual keywords can be
used as variables directly
Ex:

RESERVED KEYWORDS:

16

int get; // allowed

Karthikeya

hanu.andru@yahoo.com

1. abstract
2. as
3. base
4. bool
5. break
6. byte
7. case
8. catch
9. char
10. checked
11. class
12. const
13. continue
14. decimal
15. default
16. delegate
17. do
18. double
19. else
20. enum
21. event
22. explicit
23. extern
24. false
25. finally

9052044478

26. fixed
27. float
28. for
29. foreach
30. goto
31. if
32. implicit
33. in
34. int
35. interface
36. internal
37. is
38. lock
39. long
40. namespace
41. new
42. null
43. object
44. operator
45. out
46. override
47. params
48. private
49. protected
50. public

51. readonly
52. ref
53. return
54. sByte
55. sealed
56. short
57. size of
58. stakalloc
59. struct
60. switch
61. this
62. throw
63. true
64. try
65. type of
66. unit
67. ulong
68. unchecked
69. unsafe
70. ushort
71. used
72. virtual
73. void
74. volatile
75. while

3. set
4. value

5. where
6. yield

CONTEXTUAL KEYWORDS:
1. get
2. partial
NOTE:
Type c# *.doc in search
MAIN METHOD IN C#:
In C#.NET Main () method is the starting point of program execution.
A program can contain maximum of only one Main () method.
A Main () method must be always static because only one instance will be maintained for
the Main () method.
Return type of Main () method is either void or int.
Main () method contains one optional argument i.e. string [] args. Args is the array of
string data type.
This is used to pass the arguments to the Main () method.
A Main () method in C#.NET is always private. It cant be declared as public.
17

Karthikeya

hanu.andru@yahoo.com

9052044478

If we dont mention return type for Main () method. It gives compile time error with
error number CS1520.
ARRAYS:
An array is a variable which is used to store multiple values with the same name
Array locations are accessed with the help of index

Tree view of Array is shown in landscape page at last

SINGLE DIMENTIONAL:
If an Array contains a single roe or single column then it is known as Single
Dimensional
Ex:
A

0
10

1
20

2
30

3
40

4
50

A [5]
A
10 0
20 1
30

40 3
50 4
MULTI DIMENTIONAL:
If an Array contains more than one row and more than one column then it is known as
Multi Dimensional Array
Ex:

A [3, 3]
0

18

Karthikeya

hanu.andru@yahoo.com
0

10

50

60

20

25

30

40

20

10

9052044478

NORMAL ARRAY:
If an Array occupies a memory size of <= 64 kb then it is known as Normal Array
HUGE ARRAY:
If an Array occupies a memory size of > 64 kb then it is known as Normal Array
STATIC ARRAY:
If an Array size constant through out the program execution then it is known as Huge
Array
DYNAMIC ARRAY:
If an Array size not constant and changes during the program execution then it is known
as Huge Array
JOGGED ARRAY:
An Array with in another Array is known as Jogged Array
NOTES:
C#.NET doesnt support dynamic Arrays but VB.NET supports dynamic Arrays
In VB.NET we can change the size of the array during the program execution used ReDin
keyword
In C#.NET Arrays are treated as reference type
Arrays are object in C#.NET
For Arrays memory is not allotted in contiguous memory
Memory is allotting in heap allocation i.e. in random memory location
SYNTAX TO CREATE AN ARRAY:
Data type [ ] Array Name = new Data type [size];
(Or)
Data type [ ] Array Name = new Data type [ ] {Initializing elements};
Ex:
Int [ ] A = new int [4];
A [0] = 20;
A [1] = 30;

19

Karthikeya

hanu.andru@yahoo.com

9052044478

A [2] = 40;
A [3] = 10;
A [4] = 50;
(Or)
int [ ] A = new int [ ]{20,30,40,10,50};
A

0
20

1
30

2
40

3
10

4
50

NOTE:
If an Array is not initialized, then it will store by default values in to the array locations
like
Numeric Data types = 0
Non-Numeric Data types = NULL
Boolean Data types = False
* Example for Single Dimensional Array
Namespace CABasics
{
Class Array
{
Static void Main (string [ ] args)
{
int [ ] A = new int [ ] {20, 30, 50, 60, 70};
for (int i=0; i<5; i++)
{
Console. Write (A [ ] + /t);
}
Console.ReadLine ();
}
}
}
Namespace CABasics
{
Class String.Array
{
Static void Main (string [ ] args)
{
string [ ] A = new string [ ] { Abhi,Minni};
for (int i=0; i<5; i++)
{
Console. Write (A [ ] + /t);
20

Karthikeya

hanu.andru@yahoo.com

9052044478

}
Console.ReadLine ();
}
}
}
* foreach loop in Arrays:
SYNTAX:
foreach (Data type variable name in List)
{
Statements
.
.
}
Namespace CABasics
{
Class Array1
{
Static void Main (string [ ] args)
{
string [ ] A = new string [ ] { Abhi,Minni};
foreach (string s in A)
{
Console. Write (s + /t);
}
Console.ReadLine ();
}
}
}
NOTE:
In foreach loop at iteration the respective value of the list is copied in to the foreach
variable
In the above example in 1st iteration s will contain a value Abhi
In 2nd iteration s will contain a value Minni
A foreach statement always iterates through the whole array. If you want only to iterate
through a known of an array
A foreach statement always iterates from index zero through index Length -1. If you want
to iterate backwards, its not possible
If the body of the loop needs to know the index of the element rather than just the value
of the element, you will have a for statement
If you need to modify the elements of the array, you will have to use a for because foreach
statement is read only
21

Karthikeya

hanu.andru@yahoo.com

9052044478

METHODS N PROPERTIES WITH ARRAY OBJECT:


PROPERTIES:
Length: - This property returns the size of the Array
A. Length 5
Rank: - This property returns the dimension of the Array
A. Rank 1
If Array is 2 Dimensional then rank is 2
METHODS:
Copy to (Destination Array, index)
A. Copy to (B, 0);
This method is used to copy elements of one Array to another Array
* Example for Array objects
Namespace CABasics
{
Class Array1
{
Static void Main (string [ ] args)
{
string [ ] A = new string [ ] { C,C++,.NET,Java,Ajax};
string [ ] B = new string [10];
Console.WriteLine (Elements of Array A are...);
foreach (string s in A)
{
Console. Write (s + /t);
}
Console.WriteLine (Rank of Array A is...+A.rank);
A. Copy to (B, 0);
Console.WriteLine (Elements of Array B are...);
foreach (string s in B)
{
Console. Write (s + /t);
}
Console.ReadLine ();
}
}
}
ARRAY CLASS:

22

Karthikeya

hanu.andru@yahoo.com

9052044478

In .NET we have a separate class for array known as System. Array


This class will provide various methods to work with Array

Array. Binary search (Array name, Search value);


Array. Clear (Array name, [index], [length]);
Array. Copy (Source Array name, Destination, Array name, length);
Array. Reverse (Array name, [index], [length]);
Array. Sort (Array name, [index], [length]);

* Array. Binary Search: This method is used to search an element in a sorted array used
Binary search method
It returns an integer value

If search element is found this method will return positive integer i.e. index
value of element in Array

If search element is not found then this method will return a negative value
Ex:
A

0
10

1
20

2
30

3
40

Array. Binary search (A, 40);


Array. Binary search (A, 65);
Array. Binary search (A, 48);
Array. Binary search (A, 32);

4
50

5
60

6
70

3
-6
-4
-3

NOTE:
To use Array. Binary Search, Array must be in Sorter order
* Array. Clear ():

This method is used to initializing the default values in to the Array location
Ex:
0
1
2
3
4
A 20
30
40
10
50
Array. Clear (A): 0
A 0

1
0

2
0

3
0

4
0

Array. Clear (A, 1, 3): 0


A 20

1
0

2
0

3
0

4
50

23

Karthikeya

hanu.andru@yahoo.com

9052044478

* Array. Copy ():


This method is used to required elements from one Array to another Array
To copy the required from required location in destination Array
SYNTAX:
Array. Copy (Source Array name, Source index,
destination Array name, destination index, length)
Ex: Array. Copy (A, 2, B, 4, 4);
0
1
2
3
4
5
6
7
A
20 40 50 60 10 30 70 20

B
0

* Array. Reverse ():


This method is used to reverse the elements of the Array
Ex:
0
1
2
3
4
20
50
10
40
60 A
Array. Reverse (A):
0
1
60
40

2
10

3
50

4
20

Array. Reverse (A, 2, 3):


0
1
2
20
50
60

3
40

4
10

* Array. Sort ():


This method is used to sort the elements of the Array in ascending order
Ex:
0
1
2
3
4
20
50
10
40
60 A
Array. Sort (A):
0
1
10
20

2
40

3
50
24

4
60

Karthikeya

Array. Sort (A, 2, 3):


0
1
20
10

hanu.andru@yahoo.com

2
40

3
50

4
60

9052044478

* Example
Namespace CABasics
{
Class Array1
{
Static void Main (string [ ] args)
{
int [ ] A = new int [ ] {20, 50, 30, 10, 60, 40};
int [ ] B = new int [10];
int Searchvalue;
Console.WriteLine (Enter search element...);
Searchvalue = Convert. To int32 (Console.ReadLine ());
Array. Sort ();
Console.WriteLine (Sorted Array is...);
foreach (int s in A)
{
Console.Write (i+/t);
}
int f= Array.Binarysearch (A.serachvalue);
if (f>=0)
{
Console.WriteLine (Element is found...);
}
else
{
Console.WriteLine (Element is not found...);
}
foreach (string s in A)
{
Console. Write (s + /t);
}
Array.Reverse (A);
Console.WriteLine (Reversed Array is...);
foreach (string s in A)
{
Console. Write (s + /t);
}
Array. Copy (A, B, A. length);
Console.WriteLine (Elements of Array B are...);
foreach (string s in B)

25

Karthikeya

hanu.andru@yahoo.com

9052044478

{
Console. Write (s + /t);
}
Array. Clear (A, 0, A.length);
Console.WriteLine (Elements of Array A after clearing...);
foreach (string s in A)
{
Console. Write (s + /t);
}
Console.ReadLine ();
}
}
}
WORKING WITH TWO-DIMENSIONAL ARRAY:
SYNTAX: * int [ , ] A = new int [2, 3];
A [0, 0] = 10;
A [0, 1] = 20;
A [0, 2] = 30;
A [1, 2] = 40;
A [1, 1] = 50;
A [1, 2] = 60;
A

10

20

30

40

50

60

(Or)
* int [ , ] = new int [2, 3]{{10, 20, 30}, {40, 50, 60}};
(Or)
* int [ , ] = new int [ , ]{{10, 20, 30}, {40, 50, 60}};
* Example
Namespace CABasics
{
Class cls2DArray
{
Static void Main (string [ ] args)
{
int [ , ] A = new int [2, 3 ]{{10, 20, 30}, {40, 50, 60}};
Console.WriteLine (Elements of 2 Dimensional Array are ...);
for (int r=0; r<2; r++)
{
for (int c=0; c<3; c++)

26

Karthikeya

hanu.andru@yahoo.com

9052044478

{
Console.WriteLine (A[r, c] +\t);
}
Console.WriteLine ();
}
Console.ReadLine ();
}
}
}
UNDERSTANDING VLUES AND REFERENCES:
* All primitive types such as int are called value types. When you declare an int variable, the
compiler generates code that allocates a block of memory enough to hold an integer
* Class types such as objects are handled differently. When you declare an object variable, the
compiler does not generates code that allocates a block of memory big enough to hold an object.
* it allot a small piece of memory that is enough to store the address of another block of memory
* values types are sometimes called as direct types, and reference types are sometimes called
indirect types
HOW COMPUTER MEMORY IS ORGANIZED:
*OS and runtimes frequently divide the memory used for holding data into two separate chunks
* these two chunks of memory are traditionally called the stack and the heap
* when you call a method, the memory required for its parameters and its local variables is
always allocate from the stack
* when method is finished the memory for variables is automatically released back to the stack
and they ready to use again
* when you create an object the memory allocates always from the heap. When the last reference
to that object disappears, the memory used by the object becomes available for reuse
* stock memory is organized like a stack of boxes piled on top of each other. When method
finishes, all its boxes are removed from the stack
* heap memory is like a large pile of boxes strewn around a room rather than stacked neatly on
top of each other
* each box has a label indicating whether it is in use or not
* although the object itself stored in the heap, the reference to the object is stored in the stack
* heap memory is not infinite. If heap memory is exhausted the new operator will throw an out
of memory exception and the object will not be created
BOXING N UNBOXING:
BOXING
1. Converting a value type variable to
reference type
2. It supports 2 types
* Implicit Boxing
* Explicit Boxing

27

UNBOXING
3. Boxing takes 20 times more time as
compared to normal initialization
1. Converting a Boxing variable back to
value type
2. It supports only one type
* Explicit Boxing

Karthikeya

hanu.andru@yahoo.com

9052044478
3.

Un boxing takes 4 times more time


as compared to normal
initialization

* Example
Namespace CABasics
{
Class clsBoxing
{
Static void Main (string [ ] args)
{
int i = 10; // it stores in static memory allocation
object o = i; // Implicit boxing
object x = (object) i; // Explicit boxing
int j = (int) i; // Explicit boxing
Console.WriteLine (Value of i is ...+ i);
Console.WriteLine (Value of o is ...+ o);
Console.WriteLine (Value of x is ...+ x);
Console.WriteLine (Value of j after un boxing is ...+ j);
Console.ReadLine ();
}
}
}
NOTE: We write it like this object o = 10;
DRAWBACK OF REFERNCE TYPES:
In the reference variable, changes the value of the location which it is referring, it also
affects the other variables which are referring the same location
d

c
a

20

28

Karthikeya

hanu.andru@yahoo.com

9052044478

In the above figure (a, b, c, and d) are referring to the same locations
If any reference variable (a, b, c and d) changes the location of 20 values
It automatically effects to other references also
CLASS:

A class is a group of things which possess same common similarities.


We can call the class members through the help of the object
An object is an instant of class.
Every object will represent all the following of the class

MEMBERS OF CLASS:
In C# a class can contain 7 types of members
1. Data fields
2. Methods/Functions
3. Constructors
4. Destructors
5. Properties
6. Events
7. Indexers
CLASS DIAGRAM:
Class Name
Data fields
Properties
Indexers
Methods
Constructors
Destructors
Events
DECLARING AN OBJECT IN C#:
SYNTAX:
Access specify class class name
{
Code
29

Karthikeya

hanu.andru@yahoo.com

9052044478

.
.
}
Access specifies are 5 types they are
* Public
* Private
* Protected
* Internal
* Protected Interval
Internal is default in C#...
CREATING AN OBJECT FOR A CLASS:
SYNTAX:
Class name object name = new class name ();
Ex: Employee obj = new Employee ();
* Example on class
ClsEmployee
int Empid;
string Ename;
string Eaddress;
int age;
Public void Getdata ();
Public void Display ();
Namespace CABasics
{
class clsEmployee
{
int Empid, age;
string Ename, Eaddress;
public void Getdata ()
{
Console.WriteLine (Enter Employee Details);
Empid = Convert. To int32 (Console.ReadLine ());
Ename = Console.ReadLine ();
Eaddress = Console.ReadLine ();
age = Convert. To int32 (Console.ReadLine ());
}
public void Display ()
{
Console.WriteLine (Employee Id is + Empid);

30

Karthikeya

hanu.andru@yahoo.com

9052044478

Console.WriteLine (Employee name is + Ename);


Console.WriteLine (Employee Address is + Eaddress);
Console.WriteLine (Employee age is + age);
}
}
class clsExample1
{
static void Main ()
{
clsEmployee obj = new clsEmployee ();
obj.Getdata ();
obj.Display ();
Console.ReadLine ();
}
}
}
* Example
ClsEmpSalary
int Empid;
string Ename;
double Basic, DA;
double HRA, Gross;
Public void Getdata ();
Public void Calculate ();
Public void Display ();
DA = 40% of Basic
HRA = 20% of Basic
Namespace CAB Asics
{
class clsEmpSalary
{
int Empid;
string Ename;
double Basic, DA, HRA, Gross;
public void Getdata ()
{
Console.WriteLine (Enter Employee Details);
Empid = Convert. To int32 (Console.ReadLine ());
Ename = Console.ReadLine ();
Eaddress = Console.ReadLine ();
Basic = Convert. To Double (Console.ReadLine ());
}
public void Calculate ()

31

Karthikeya

hanu.andru@yahoo.com

9052044478

{
DA = 0.4 * Basic;
HRA = 0.2 * Basic;
Gross = Basic + DA + HRA;
}
public void Display ()
{
Console.WriteLine (Employee Id is + Empid);
Console.WriteLine (Employee name is + Ename);
Console.WriteLine (Employee Basic is + Basic);
Console.WriteLine (Employee DA is + DA);
Console.WriteLine (Employee HRA is + HRA);
Console.WriteLine (Employee Gross salary is + Gross);
}
}
class clsExample1
{
static void Main ()
{
clsEmpSalary obj = new clsEmpSalary ();
obj.Getdata ();
obj.Calculate ();
Console. Clear ();
obj.Display ();
Console.ReadLine ();
}
}
}
FEATURES OF OBJECT ORIENTED PROGRAMMING:
* Abstraction
* Encapsulation
* Polymorphism
* Inheritance
* ABSTRACTION:
Abstraction is hiding the implementation and providing result or service.
Ex:
If we go to a restaurant and order a Biryani, Biryani preparation is hidden but Biryani is
served.
Abstraction is of 2 kinds
* Data Abstraction
* Function Abstraction

32

Karthikeya

hanu.andru@yahoo.com

9052044478

DATA ABSTRACTION:
Used this we can provide Abstraction for the data fields of the class by used properties
and Indexers
FUNCTIONAL ABSTRACTION:
When we call any function outside the class. Code of the function is hidden but we get the
Result
* ENCAPSULATION:
Binding the data members of a class along with function of the class is known as
Encapsulation
Encapsulation has two purposes
1. To combine methods and data inside a class; in other words, to support
classification
2. To control the accessibility of the class; in other words, to control the use of the
class
POLYMORPHISM:
Polymorphism is providing different functionalities of implementations for the sane
function operator
This word has been derived from Greek word. Its meaning is poly means Many.. morphy
means forms or phases
Polymorphism is achieved in 2 ways
* Function overloading
* Operator overloading
INHERITANCE:

The main purpose of inheritance is code reusability


Creating a new class from an existing class is known as inheritance
The existing class is known as Base class or parent class
The newly created class is known as Derived class or Child class
When we inherit a new class the existing class members can be accessed in newly created
class based on their accessibility levels

TYPES OF INHERITANCE:
* Single Inheritance
* Multiple Inheritance
* Multiple Inheritance

33

Karthikeya

hanu.andru@yahoo.com

9052044478

* Hybrid Inheritance
SINGLE INHERITANCE:
Creating a single new class from a single Existing class is known as single
Inheritance

Class A

Parent

Class B

Child

MULTIPLE INHERITANCE:
Creating a new class from two or more existing classes is known as multiple
Inheritance
Class A

Class B

Class C
In the above fig class A and class B are parent or Base classes for class C
class C is derived for class A and class B
All the members of class A and class B cab be used in class C based on their accessibility
levels
Not possible in c# with both parents as classes.
One interface and one parent is allowed for multiple.
MULTI-LEVEL INHERTIANCE:
Creating a new class from already derived class is known as multilevel Inheritance
Class A

Class B

Class C
34

Karthikeya

hanu.andru@yahoo.com

9052044478

In the above figure class B is derived from class A and class C is derived from class B
* class A is parent /base class for class B and super class for class C
* class B is parent /base class for class C and child class for class A
* class C is Derived class for class B
All members of class A can be used in class B based on their accessibilities
All members of class A and class B can be used in class C based on their accessibility
Levels
HYBRID INHERITANCE:
This is the combination of multiple and multilevel inheritance
Class A

Class B

Class C

Class D
In the figure class C is created by used class A and class B. This is multiple inheritance
class D is created from class C which is already derived. This is multilevel inheritance
class A and class B are base classes for class C and super classes for class D
class C is parent class for class D and derived class for class A and class B
class D is derived class for class C
* Example
clsCompany
string Cname;
string Caddress;
int RegNo;
string ConNum;
Public void Getdata ();
Public void Display ();
ClsEmployee
int Empid;
string Ename;
string Eaddress;
int Eage;

35
Public void GetEdata ();
Public void EDisplay ();

Karthikeya

hanu.andru@yahoo.com

9052044478

Namespace CAInheritance
{
class clsCompany
{
int RegNo;
string Cname, Caddress, Cnum;
public void Getdata ()
{
Console.WriteLine (Enter Employee Details);
RegNo = Convert. To int32 (Console.ReadLine ());
Cname = Console.ReadLine ();
Caddress = Console.ReadLine ();
Cnum = Console.ReadLine ();
}
public void Display ()
{
Console.WriteLine (Company details are);
Console.WriteLine (RegNo is + RegNo);
Console.WriteLine (Name is + Cname);
Console.WriteLine (Address is + Caddress);
Console.WriteLine (Contact number is + Cnum);
}
}
class clsEmpSalary: clsCompany
{
int Empid;
string Ename;
double Basic, DA, HRA, Gross;
public void Getdata ()
{
base.Getdata ();
Console.WriteLine (Enter Employee Details);
Empid = Convert. To int32 (Console.ReadLine ());
Ename = Console.ReadLine ();
Eaddress = Console.ReadLine ();
Eage = Convert. To int32 (Console.ReadLine ());
}
public void Display ()

36

Karthikeya

hanu.andru@yahoo.com

9052044478

{
base. Display ();
Console.WriteLine (Employee Id is + Empid);
Console.WriteLine (Employee name is + Ename);
Console.WriteLine (Employee Address is + Eaddress);
Console.WriteLine (Employee age is + age);
}
}
class clsExample1
{
static void Main ()
{
clsEmpEmployee obj = new clsEmpEmployee ();
obj.GetEdata ();
Console. Clear ();
obj.EDisplay ();
Console.ReadLine ();
}
}
}
NOTE:
base is the keyword which is used to access the Base class members with in the Derived
class

base is the default object which is used to access the Base class member in
Derive class

This is the keyword used to access the current class members


* Example on Multilevel
clsCompany
int Regno;
string Cname;
string Caddress;
string Cnum;
Public void GetCdata ();
Public void DisplayCdata ();

clsEmployee
int Empid, Eage;
string Ename;
string Eaddress;
Public void GetEdata ();
clsSalary
Public void
DisplayEdata ();
double Basic, Da;
double Hra, Grass;
37
Public void GetSdata ();
Public void Calculate ();
Public void DisplaySdata ();

Karthikeya

hanu.andru@yahoo.com

9052044478

Namespace CAMLInheritance
{
class clsCompany
{
int RegNo;
string Cname, Caddress, Cnum;
public void Getdata ()
{
Console.WriteLine (Enter Employee Details);
RegNo = Convert. To int32 (Console.ReadLine ());
Cname = Console.ReadLine ();
Caddress = Console.ReadLine ();
Cnum = Console.ReadLine ();
}
public void Display ()
{
Console.WriteLine (Company details are);
Console.WriteLine (RegNo is + RegNo);
Console.WriteLine (Name is + Cname);
Console.WriteLine (Address is + Caddress);
Console.WriteLine (Contact number is + Cnum);
}
}
class clsEmpSalary: clsCompany
{
int Empid;
string Ename;
double Basic, DA, HRA, Gross;
public void Getdata ()
{
base.GetCdata ();
Console.WriteLine (Enter Employee Details);
Empid = Convert. To int32 (Console.ReadLine ());
Ename = Console.ReadLine ();
Eaddress = Console.ReadLine ();
Eage = Convert. To int32 (Console.ReadLine ());

38

Karthikeya

hanu.andru@yahoo.com

9052044478

}
public void DisplayCdata ()
{
base. Display ();
Console.WriteLine (Employee Id is + Empid);
Console.WriteLine (Employee name is + Ename);
Console.WriteLine (Employee Address is + Eaddress);
Console.WriteLine (Employee age is + age);
}
}
class clsSalary: ClsEmployee
{
double Basic, Da, Hra, Gross;
public void GetSdata ()
{
base. GetEdata ();
Cinsole.WriteLine (Enter Employee Basic Salary);
Basic = Convert. To intDouble (Console.ReadLine ());
}
public void Calculate ()
{
Da = 0.4*Basic;
Hra = 0.2*Basic;
Gross = Da + Hra +Basic;
}
public void DisplaySdata ()
{
base. DisplayEdata ();
Console.WriteLine (Employee salary details are...);
Condole.WriteLine (Basic Salary is + Basic);
Condole.WriteLine (Basic Da is + Da);
Condole.WriteLine (Basic Hra is + Hra);
Condole.WriteLine (Basic Gross is + Gross);
}
}
class clsExample1
{
static void Main ()
{
clsSalary obj = new clsSalary ();
obj.GetSdata ();
Console. Clear ();
obj. DisplaySdata ();
Console.ReadLine ();
}
}

39

Karthikeya

hanu.andru@yahoo.com

9052044478

}
ACCESS SPECIFIERS:

These are used to give restriction to the class members, classes, structures,
enums and delegates

They are 5 types


* private
* protected
* internal
* protected internal
* public
PRIVATE:

private members are accessible with in the same class which they are
declaring
PROTECTED:

protected members are accessible with in the same class and with in the
Derived classes

Derived class may be present in the same Namespace or in different


Namespace
INTERNAL:
internal members are accessible in any class with in the same Namespace.
The class might be Derived or Non-Derived

internal members cant be accessed outside the Namespace if the class is


Derived also...
PROTECTED INTERNAL:

These are accessed in any class with in the same Namespace and in Derived
classes outside the Namespace
PUBLIC:

public members are accessed in any class with in the same Namespace or
outside the Namespace
Same Namespace
same
derived
other
class
class
class

40

Outside the Namespace


derived
other
class
class

Karthikeya
private
protected
internal
protected internal
public

hanu.andru@yahoo.com
Yes
Yes
Yes
Yes
Yes

No
Yes
Yes
Yes
Yes

No
No
Yes
Yes
Yes

9052044478
No
Yes
Yes
No
Yes

No
No
No
No
Yes

CONSTRUCTOR:

A constructor is a method with in the class with the same name as class
name

A constructor is invoked automatically when an object is created for that


class

A constructor is used to initialize the data fields of a class


TYPES OF CONSTRUCTORS:
DEFAULT CONSTRUCTORS:

A default constructor is a parameter less constructor

Default constructor is invoked when an object is created with out any


parameters
USER DEFINED DEFAULT CONSTRUCTOR:

With in a class programmer defines a constructor with out passing any


arguments which is known as user defined
* Example on user defined constructor
Namespace CAConstructor
{
class clsEmployee
{
int Empid, age;
string Ename, Eaddress;
public clsEmployee ()
{
Empid=101; age=25; Ename=Abhi; Eaddress=Hyderabad;
}
public void Display ()
{
Console.WriteLine (Employee Id is + Empid);

41

Karthikeya

hanu.andru@yahoo.com

9052044478

Console.WriteLine (Employee name is + Ename);


Console.WriteLine (Employee Address is + Eaddress);
Console.WriteLine (Employee age is + age);
}
}
class clsExample1
{
static void Main ()
{
clsEmployee obj = new clsEmployee ();
obj.Display ();
Console.ReadLine ();
}
}
}

At the time of execution compiler will search for the user defined constructor
initially

If user defined default constructor is not available then system will create its
own constructor and stores the default values in to the data fields

This is known as system defined


* Example on system defined constructor
Namespace CAConstructor
{
class clsEmployee
{
int Empid, age;
string Ename, Eaddress;
public void Display ()
{
Console.WriteLine (Employee Id is + Empid);
Console.WriteLine (Employee name is + Ename);
Console.WriteLine (Employee Address is + Eaddress);
Console.WriteLine (Employee age is + age);
}
}
class clsExample1
{
static void Main ()
{
clsEmployee obj = new clsEmployee ();
obj.Display ();
Console.ReadLine ();
}

42

Karthikeya

hanu.andru@yahoo.com

9052044478

}
}
DISADVANTAGES:

If we create number of objects, same values are stored in to all object data
fields

To overcome this problem we use parameterized constructor


* Example on parameterized constructor
Namespace CAConstructor
{
class clsEmployee
{
int Empid, age;
string Ename, Eaddress;
public clsEmployee (int Id, string s, string Ad, int A)
{
Empid=Id; Ename=s; Eaddress=Ad; age=A;
}
public void Display ()
{
Console.WriteLine (Employee Id is + Empid);
Console.WriteLine (Employee name is + Ename);
Console.WriteLine (Employee Address is + Eaddress);
Console.WriteLine (Employee age is + age);
}
}
class clsExample1
{
static void Main ()
{
clsEmployee obj1 = new clsEmployee (102, sai, Hyd, 25);
clsEmployee obj2 = new clsEmployee (101, raj, Ban, 24);
obj1.Display (); obj2.Display ();
Console.ReadLine ();
}
}
}
COPY CONSTUCTOR:

If we want to copy or use existing object data fields, then we use copy
constructor

43

Karthikeya

hanu.andru@yahoo.com

9052044478

Copy constructor is used to copy the existing object data fields in to newly
created object data fields

Copy constructor will have one argument of the same class type

Existing object data fields are stored used constructor then constructor is
accepted by the user
* Example on copy constructor
Namespace CAConstructor
{
class clsEmployee
{
int Empid, age;
string Ename, Eaddress;
public clsEmployee () // default constructor
{
Empid=101; age=25; Ename=Abhi; Eaddress=Hyderabad;
}
public clsEmployee (int Id, string s, string Ad, int A)// parameterized
{
Empid=Id; Ename=s; Eaddress=Ad; age=A;
}
public clsEmployee (clseEmployee objTemp)
{
Empid = objTemp.Empid;
Ename = objTemp.Ename;
Eaddress = objTemp.Eaddress;
Eage = objTemp.Eage;
}
public void Display ()
{
Console.WriteLine (Employee Id is + Empid);
Console.WriteLine (Employee name is + Ename);
Console.WriteLine (Employee Address is + Eaddress);
Console.WriteLine (Employee age is + age);
}
}
class clsExample1
{
static void Main ()
{
clsEmployee obj1 = new clsEmployee ();
clsEmployee obj2 = new clsEmployee (102, sai, Hyd, 25);
clsEmployee obj3 = new clsEmployee (obj1);
clsEmployee obj4 = new clsEmployee (obj2);
obj1.Display (); obj2.Display ();

44

Karthikeya

hanu.andru@yahoo.com

9052044478

obj3.Display (); obj4.Display ();


Console.ReadLine ();
}
}
}
PRIVATE CONSTRUCTOR:

If a constructor is defined used private access specifies then it is known as


private constructor

It cant be call from outside the class

It can be call with in the class only

Generally private constructor is used in remoting concepts


STATIC CONSTRUCTOR:
* Example without static variable
Namespace CAConstructor
{
class clsSample
{
public clsSample ()
{
i=100;
}
public void display ()
{
Console.WriteLine (Value of I is + i);
i++;
}
}
class clsNonstatic
{
static void Main ()
{
clsEmployee obj1 = new clsEmployee ();
obj1.Display ();
clsEmployee obj2 = new clsEmployee ();
obj2.Display ();
Console.ReadLine ();
}
}
}
* Example without static variable

45

Karthikeya

hanu.andru@yahoo.com

9052044478

Namespace CAConstructor
{
class clsSample
{
int i; static int j;
public clsSample ()
{
i=100;
}
static clsSample ()
{
j=100;
}
public void display ()
{
Console.WriteLine (Value of I is + i);
i++;
Console.WriteLine (Value of I is + i);
i++;
}
}
class clsNonstatic
{
static void Main ()
{
clsEmployee obj1 = new clsEmployee ();
obj1.Display ();
clsEmployee obj2 = new clsEmployee ();
obj2.Display ();
clsEmployee obj2 = new clsEmployee ();
obj2.Display ();
Console.ReadLine ();
}
}
}

All static members will have a common instance for all the object of the
class

Where as all non-static members will have separate instance for each class

All static data fields can be initialized in a non-static constructor


Ex:
public clsSample ()
{
i=100; j=101; // this is allowed...
}

46

Karthikeya

hanu.andru@yahoo.com

9052044478

When we initialize a static data fields in a non-static constructor. It looses its


static nature
Ex:
static clsSample ()
{
j=100; i=100; // this is not allowed
}

A non-static variable cant be initialized in static constructor

A static data field can be initialized in both static and non-static constructor
but priority is given to the non-static constructor
Ex:
public clsSample ()
{
i=100; j=101; // this is allowed
}
static clsSample ()
{
j=100; // this is allowed
}
STATIC Vs DYNAMIC VARIABLES:
STATIC
1.
Initialized only once
during the beginning of
execution
2.
Returns their old values
3.
Can be only private or
local, cant be public

DYNAMIC
1. Reinitialized every time
for each object
2. Cant return their old
value
3. Can be local or public

POLYMORPHISM:

Polymorphism is achieving by used two ways


* Function Overloading
* Function Overriding

FUNCTION OVERLOADING:

Assigning additional work to an existing function other than the original work
is known as function overloading

We overload a function in two cases


* When number of parameters/arguments are changed
* When data types of the arguments are changed

47

Karthikeya

hanu.andru@yahoo.com

9052044478

* WHEN NUMBER OF ARGUMENTS CHANGED:


public int add (int a, int b)
{
int r = a+b;
return r;
}

Above function can be used to add only two integers

To perform an addition of three integers we cant use this above function

Add (10, 20) can be used but add (10, 20, 30) same function for three
arguments in the following way
public int add (int a, int b, int c)
{
int r = a+b+c;
return r;
}
* METHOD SIGNATURE / FUNCTION SIGNATURE:

A method signature/function signature can be identifying by depending


their
* Access specifies of the function
* Return type of the function
* Function name
* Number of arguments
* Data types of arguments
With same signature:
public int add (int a, int b)
{

}
public int add (int x, float b)
{

}
With different signature:
public int add (int a, int b)
{

}
public int add (int a, int b, int c)
{

48

Karthikeya

hanu.andru@yahoo.com

9052044478

}
public double add (int a, double b)
{

}
public double add (double a, double b)
{

}
public void add (int a, int b)
{

}
FUNCTION / METHOD OVERRIDING:

Providing different functionality for the same function is known as function


overriding

When we override a function, function signature doesnt change

Function overriding is implementing in INHERITANCE


FUNCTION OVERLOADING Vs FUNCTION OVERRIDING:
OVERLOADING
1.
Function signatures are
different
2.
Function will have existing function
code and new code (i.e. function need to
perform overload function work based on
requirement)
3.
Can be implemented with
or without inheritance
4.
Known as static
polymorphism (Early binding /
compile time polymorphism)
* Example for function overloading
clsCompany
int Empid, Eage;
string Ename;
string Eaddress; 49
Public void Getdata ();
Public void Displaydata ();

OVERRIDING
1. Function signatures are
same. Doesnt change
2. In this newly assigned code is
execute and already existing code of
the function is ignored
3. Can be implement with in
Inheritance only
4. Known as Dynamic
polymorphism (Late
binding / runtime
polymorphism)

Karthikeya

hanu.andru@yahoo.com

9052044478

In this class Getdata () contains code to accept all the data fields like Empid,
Eage, Ename and Eaddress

During the expression of the company, company divides the employee in to


Manager following rules
Age is fixed >= 45 years
Address is same as the company address

While accepting the data of the Manager, it isnt required to accept Eage and
Eaddress

For Non-managers we need to accept all the data fields


SOLUTION:

For this we have to derive to new classes from clsEmployee known as


clsManager and clsNon-manager

We overriding the methods Getdata () and Displaydata () in clsManager

clsEmployee

clsManager

clsNonManager

CLASS DIAGRAM:
clsEmployee
int Empid,Eage;
string Ename;
string Eaddress;
Public virtual void Getdata ();
Public virtual void Displaydata ();
clsManager
int Bonus;
Public override void Getdata ();
Public override void Displaydata ();

50

Karthikeya

hanu.andru@yahoo.com

9052044478

Namespace CAfunctionOverride
{
class clsEmployee
{
protected int Empid, age;
protected string Ename, Eaddress;
public virtual void GetEmpdatat()
{
Console.WriteLine (Enter empid, name, address and age);
Empid = Convert.Toint32 (Console.ReadLine());
Ename = Console.ReadLine();
Eaddress = Console.ReadLine();
Eage = Convert.Toint32 (Console.ReadLine());
}
public virtual void DisplayEmpdata ()
{
Console.WriteLine (Employee Id is + Empid);
Console.WriteLine (Employee name is + Ename);
Console.WriteLine (Employee Address is + Eaddress);
Console.WriteLine (Employee age is + age);
}
}
class clsManager : clsEmployee
{
int Bonus;
public override GetEmpdata()
{
Console.WriteLine (Enter Manager Details);
Empid = Convert.Toint32 (Console.ReadLine( ));
Ename = Console.ReadLine();
Bonus = Convert.Toint32 (Console.ReadLine( ));
}
public override DisplayEmpdata()
{
Console.WriteLine (Manager Id is + Empid);
Console.WriteLine (Manager name is + Ename);
Console.WriteLine (Manager Bonus is + Bonus);
}
}
class clsFunOverride
{
static void Main ()
{
clsManager objM = new clsManager ( );
objM.GetEmpdata (); objM.DisplayEmpdata ();

51

Karthikeya

hanu.andru@yahoo.com

9052044478

Console.ReadLine ();
}
}
}
VIRTUAL METHOD OR FUNCTION:
A virtual method is declaring used virtual keyword..
A virtual function can be overridden in one of its derived classes..
OVERRIDING A METHOD OR FUNCTION:

To override a method use the override keyword..


Generally we override the virtual methods or functions..

NOTE:

A virtual class cant contain abstract methods. No keyword is used to declare


virtual class but for creating methods. We use virtual keyword..

A virtual function contains both declaration and definition of method. Where


as an abstract function contains only declaration
ABSTRACT FUNCTIONS:

A function which contains only declaration and does not contain any
functionality is known as abstract function

An abstract function is declared used abstract keyword

An abstract function must be overridden in one of its derived classes

An abstract function can be declared only with in abstract class

If an abstract functions declare in non abstract class. Then compilation error


occurs
ABSTRACT CLASS:

A class which contains one or more abstract functions is known as abstract


class

Abstract class should be declared used abstract keyword

An abstract class can not be initialized directly

An abstract class can contain both abstract and non abstract functions

An abstract class should be used to derive new class


Example:
clsEmployee (abstract)
int Empid,Eage;
string Ename;
string Eaddress;

52
Public abstract void GetEmpdata ();
Public abstract void Display ();

Karthikeya

hanu.andru@yahoo.com

9052044478

clsManager
int Bonus;
Public override void GetEmpdata ();
Public override void Display ();
Namespace CAabstract
{
abstract class clsEmployee
{
protected int Empid, age;
protected string Ename, Eaddress;
public abstract void GetEmpdata ();
public virtual void Display ();
}
class clsManager : clsEmployee
{
int Bonus;
public override GetEmpdata()
{
Console.WriteLine (Enter Manager Details);
Empid = Convert.Toint32 (Console.ReadLine( ));
Ename = Console.ReadLine();
Bonus = Convert.Toint32 (Console.ReadLine( ));
}
public override DisplayEmpdata()
{
Console.WriteLine (Manager Id is + Empid);
Console.WriteLine (Manager name is + Ename);
Console.WriteLine (Manager Bonus is + Bonus);
}
}
class clsAbstractExample
{
static void Main ()
{
clsManager objM = new clsManager ( );
objM.GetEmpdata ();
objM.DisplayEmpdata ();

53

Karthikeya

hanu.andru@yahoo.com

9052044478

Console.ReadLine ();
}
}
}
INTERFACES:

A class which contains all abstract methods is known as an interface


An interface is declared used interface keyword
An interface cant be instantiated directly
An interface can contain only the following members of class
* Methods (Abstract only)
* Properties
* Events
* Indexers
Interface is used to implement multiple inheritances in c#.net
All the methods of an interface must be overridden in derived classes
By default all members of interface are public. All methods are abstract
An interface can be used to derive another interface

ABSTRACT Vs INTERFACE

ABSTRACT
1.
overriding of virtual methods
in derived class is optional
2.
by default all members of
abstract class are private

INTERFACE
3.
contain both abstract and non
abstract methods
4.
declaring used abstract
keyword

54

Karthikeya

hanu.andru@yahoo.com

5.
can contain all the members
of the class say data fields, methods,
properties, constructors, destructors,
events and indexers
6.
cant be instantiated
directly
7.
cant be used to implement
multiple inheritances
8.
use abstract keyword for
declaring all abstract functions

9052044478

3. contain only abstract


methods
4. declaring used interface
keyword
5. can contain 4 members of
class namely properties,
methods(abstract), indexers
and events
6. cant be instantiated
directly
7. used to implement multiple
inheritances
8. do not use abstract keyword
for declaring abstract
functions

1. overriding of abstract
methods in derived class is
compulsory
2. by default all members of
interface are public..
NOTE:

By default all interface methods are of protected i.e. access specifies is by


default protected for them
Example:

clsEmployee (interface)
void GetEmpdata ();
void DisplayEmpdata ();

clsManager
int Bonus, Empid; string Ename;
Public override void GetEmpdata ();
Public override void Display ();

Namespace CAinterface
{
interface clsEmployee
{
void GetEmpdata ();
void DisplayEmpdata ();

55

Karthikeya

hanu.andru@yahoo.com

9052044478

}
class clsManager : clsEmployee
{
int Bonus, Empid; string Ename;
public override void GetEmpdata()
{
Console.WriteLine (Enter Employee id, Name and Bonus);
Empid = Convert.Toint32 (Console.ReadLine( ));
Ename = Console.ReadLine();
Bonus = Convert.Toint32 (Console.ReadLine( ));
}
public override DisplayEmpdata()
{
Console.WriteLine (Manager Id is + Empid);
Console.WriteLine (Manager name is + Ename);
Console.WriteLine (Manager Bonus is + Bonus);
}
}
class clsInterfaceExample
{
static void Main ()
{
clsManager obj = new clsManager ( );
obj.GetEmpdata ();
obj.DisplayEmpdata ();
Console.ReadLine ();
}
}
}
MULTIPLE INHERITANCES:
clsEmployee (interface)

clsEmployee (interface)

void GetEmpdata ();


void DisplayEmpdata ();

void GetEmpdata ();


void DisplayEmpdata ();

clsManager
int Bonus, Empid;
string Ename, Cname, Caddress;
public override void GetCdata();
public override void DisplayCdata();
public override void GetEmpdata ();
public override void DisplayEmpdata();
56

Karthikeya

hanu.andru@yahoo.com

9052044478

Namespace CAmulInterface
{
interface clsCompany
{
void GetCdata ();
void DisplayCdata ();
}
interface clsEmployee
{
void GetEmpdata ();
void DisplayEmpdata ();
}
class clsManager : clcCompany,clsEmployee
{
int Bonus, Empid;
string Ename, Cname, Caddress;
public override void GetCdata()
{
Console.WriteLine (Enter company Name and Address);
Cname = Console.ReadLine();
Caddress = Console.ReadLine( );
}
public override DisplayCdata()
{
Console.WriteLine (Company name is + Cname);
Console.WriteLine (Manager Address is + Caddress);
}
public override void GetEmpdata()
{
Console.WriteLine (Enter Employee id, Name and Bonus);
Empid = Convert.Toint32 (Console.ReadLine( ));
Ename = Console.ReadLine();
Bonus = Convert.Toint32 (Console.ReadLine( ));
}
public override DisplayEmpdata()
{
Console.WriteLine (Manager Id is + Empid);
Console.WriteLine (Manager name is + Ename);
Console.WriteLine (Manager Bonus is + Bonus);
}
}
class clsmulInheritance

57

Karthikeya

hanu.andru@yahoo.com

9052044478

{
static void Main ()
{
clsManager objM = new clsManager ( );
objM.GetCdata ();
objM.GetEmpdata ();
objM.DisplayCdata ();
objM.DisplayEmpdata ();
Console.ReadLine ();
}
}
}
NOTE:

When we derive another class from the two base classes. We have to redeclare
all the data fields and methods. This is the draw back of multiple inheritances in
C#.net
INHERITING CONSTRUCTORS:

clsEmployee
int Empid, Eage;
string Ename;
string Eaddress;
clsEmployee();
clsManager
int Bonus;
Public void Getdata ();
Public void Displaydata ();
Namespace CAinheritConstructor
{
class clsEmployee
{
protected int Empid, Eage;
protected string Ename, Eaddress;
public clsEmployee()

58

Karthikeya

hanu.andru@yahoo.com

9052044478

{
Empid=101; Eage=25;
Ename=Ram;Eaddress=Hyderabad;
}
}
class clsManager : clsEmployee
{
int Bonus, Empid; string Ename;
public clsManager()
{
Bonus=20000;
}
public void DisplayEmpdata()
{
Console.WriteLine (Manager Id is + Empid);
Console.WriteLine (Manager name is + Ename);
Console.WriteLine (Manager Address is +
Eaddress);
Console.WriteLine (Manager Age is + Eage);
Console.WriteLine (Manager Bonus is + Bonus);
}
}
class clsInherit_Constructor
{
static void Main ()
{
clsManager obj = new clsManager ( );
obj.DisplayEmpdata ();
Console.ReadLine ();
}
}
}
NOTE:

When we create object from derived class, first base class constructor is
executed. Then derived class constructor is executed

Even when we work with parameterized constructors


PROPERTIES:

Properties are used to provide data abstraction to the data fields of the class

A property never stores a value

A property is used to transfer the required values from outside the class to
data field and from data fields to outside the class

59

Karthikeya

hanu.andru@yahoo.com

9052044478

A property can contain maximum two methods or accessory. They are set and
get
* SET ACCESSORY:

Used to write or store the value in to data fields

Set accessory will have a fixed and default variable known as value

When we call a property to transfer a value in to data field, the supplied value
will come and store in value variable automatically
* GET ACCESSORY:

Get accessory is used to read the value present with in the data field of the
class
TYPES OF PROPERTIES:
* Read only property
* Write only property
* Read-Write property
* READ ONLY:

This property is used to read a value of the data field or this property returns
the value of the data field

Used read only property we cant store a value in data field

Read only property will contain only one method i.e. get method
SYNTAX:
Access specifies data type property name
{
get
{
return data field Name/any value;
}
}
* WRITE ONLY:

This property is used to write or store a value in to data field of a class


Used this property we cant read the value present in data field
Write only property will contain only one method or accessory

SYNTAX:
Access specifies data type property name
{
set
60

Karthikeya

hanu.andru@yahoo.com

9052044478

{
data field Name = value;
}
}
* READ WRITE:

This property is used to read a value present in the data field and to write a
value in to data field

This property contains 2 accessories i.e. get and set accessories


SYNTAX:
Access specifies data type property name
{
get
{
return data field Name/any value;
}
set
{
data field Name = value;
}
}
NOTE: value is default and fixed variable. We cant change it
Example:
clsEmployee
int Empid, Eage;
string Ename;
string Eaddress;
int Pempid;
string Peaddress, Pename;
***No Methods***

Namespace CAproperties
{
class clsEmployee
{
int Empid; string Ename, Eaddress;
public int Pempid
{
get { return Empid; }
set { Empid = value; }
}

61

Karthikeya

hanu.andru@yahoo.com

9052044478

public string Pename


{
get { return Ename; }
set { Ename = value; }
}
public int Pempid
{
get { return Eaddress; }
set { Eaddress = value; }
}
}
class property1
{
static void Main()
{
clsEmployee obj = new clsEmployee();
Consloe.WriteLine(Enter Employee details..);
obj.Pempid = Convert. To int 32(Console.ReadLine());
obj.Pename = Console.ReadLine();
obj.Peaddress = Console.ReadLine();
Console.Clear();
Console.WriteLine (Manager Id is + obj.Pempid);
Console.WriteLine (Manager name is + obj.Pename);
Console.WriteLine (Manager Address is + obj.Peaddress);
}
}
}
Example:
clsArthemetic
int Num1, Num2;
int Result;
int Pnum1,Pnum2;
int Presult;
Public void Add()
Public void Subtract()

Namespace CAproperties
{
class clsArthemetic
{
int Num1, Num2, Result;
public int Pnum1
{
set { Num1 = value; }

62

Karthikeya

hanu.andru@yahoo.com

9052044478

}
public int Pnum2
{
set { Num2 = value; }
}
public int Presult
{
get { return Result; }
}
public void Add ()
{
Result = Num1 + Num2;
}
public void Subtract ()
{
Result = Num1 - Num2;
}
}
class property2
{
static void Main()
{
clsArthemetic obj = new clsArthemetic ();
Consloe.WriteLine(Enter any 2 numbers..);
obj.Pnum1 = Convert. To int 32(Console.ReadLine());
obj.Pnum2 = Convert. To int 32(Console.ReadLine());
obj.Add();
Console.WriteLine (Sum is + obj.Presult);
obj.Subtract();
Console.WriteLine (Manager Address is + obj.Presult);
Console.ReadLine();
}
}
}
NOTE:

A property never accepts arguments i.e. parameters

Declaration of local variables with in the property is prohibited

By default accessibility of the accessory is same as the accessibility of the


property is public set accessory will be public and get accessory will be public
SYMMETRIC ACCESSORIES:

If accessibility of both the accessories i.e. set and get is same, then set and get
are known as symmetric accessories

63

Karthikeya

hanu.andru@yahoo.com

9052044478

Ex:
public int Pempid
{
get { return Eaddress; }
set { Eaddress = value; } // both are public..
}
ASYMMETRIC ACCESSORIES:

If accessibility of the accessories is different, then set and get are known as
asymmetric accessories
Ex:
public int Pempid
{
protected get { return Eaddress; } //set is protected..
set { Eaddress = value; } // get is public..
}
INDEXERS:

Indexers are used to provide data abstraction to the arrays

Indexers are similar to properties

Properties are used to a single data field, where as indexers are used to provide
data abstraction to multiple variables

Indexers are members of class

An indexer can contain maximum 2 accessories i.e. get and set


SYNTAX:
Access specifies data type this [ index variable ]
Ex:
public int this [ int i]
{
get
{
}
set
{

}
}
An indexer accepts arguments i.e. index value of array
Namespace CAindexer
{
64

Karthikeya

hanu.andru@yahoo.com

9052044478

class clsExample
{
int[] A = new int [10];
public int this [int i]
{
set { A[i] = value; }
get { return A[i]; }
}
}
class clsIndexers
{
static void Main()
{
clsSample obj = new clsSample();
obj [0] = 10; obj [1] = 20; obj [2] = 30;
obj [3] = 50; obj [4] = 40;
Console.WriteLine (Elements of Array are..);
for ( int i=0; i<=4; i++)
{
Console.Write (obj [0]) + \t);
}
Console.ReadLine();
}
}
}
DELEGATES:

A delegate is similar to pointer of function in C++.


A delegate is used to represent a function.
Delegates will use pointers internally.
A delegate can be used to represent a single function or multiple functions.
A delegate is declared used delegate keyword.
Delegates are the base for events.
A delegate can be declared inside the class or outside the class.

HOW TO DECLARE A FUNCTION:

Declare the delegate


Access specifies delegate return type delegate name ([argument]);

The signature of the delegate must be same as the signature of the function
that we want to represent.

To represent a function like


65

Karthikeya

hanu.andru@yahoo.com

9052044478

public void display ()


{

}
We declare a delegate keyword like
public delegate void sampleDelegate ();
Instantiate the delegate
Delegate name object = new delegate name (function name);
Ex: sampleDelegate objD = new sampleDelegate (display);
Invoke the delegate
Object name ([arguments]); // arguments are optional
Ex: objD;

Namespace CAdelegates
{
class clsDelegate1
{
static void display ()
{
Console.WriteLine (Welcome...);
}
public delegate void sampleDelegate ();
static void Main ()
{
sampleDelegate objD = new sampleDelegate (display);
objD ( );
Console.ReadLine ();
}
}
}

Namespace CAdelegates
{
class clsSample
{
public void Add (int a, int b)
{
int c = a+b;
Console.WriteLine (Sum is ...+ c);
}
public delegate void sampleDelegate2 (int x, int y);
}
class clsDelegate2
{
static void Main ()
{

66

Karthikeya

hanu.andru@yahoo.com

9052044478

clsSample obj = new clsSample ();


sampleDelegate2 objD = new sampleDelegate2 (obj.Add);
objD (40, 10);
Console.ReadLine ();
}
}
}
NOTE:

Though a delegate maintains a pointer to the function, it will not follow unsafe
code.

The code will be safe code only.


MULTI CAST DELEGATES:

Multicast delegates are used to represent more than one function which
signature is same.

That is same access specifies return type and same no of arguments and their
data type.

Namespace CAdelegates
{
class clsArthemetic
{
public void Add (int a, int b)
{
int c = a+b;
Console.WriteLine (Sum is ...+ c);
}
public void Subtract (int a, int b)
{
int c = a-b;
Console.WriteLine (Difference is ...+ c);
}
public void Multiply (int a, int b)
{
int c = a*b;
Console.WriteLine (Product is ...+ c);
}
public void Divide (int a, int b)
{
int c = a/b;
Console.WriteLine (Quotient is ...+ c);
}
public delegate void McDelegate (int x, int y);
}

67

Karthikeya

hanu.andru@yahoo.com

9052044478

class clsMcDelegate
{
static void Main ()
{
clsArthematic obj = new clsArthematic ();
McDelegate objD = new McDelegate (obj.Multiply);
objD = objD + obj.Subtract ();
objD = objD + obj.Divide ();
objD = objD + obj.Add ();
Console.ReadLine ();
}
}
}
NOTE:
Multicast delegates can be used for functions with same signature only.
To add more than one function for a delegate then use + = operator.
objD += obj.Add;
objD += obj.Subtract;

To remove reference of any function from the delegate use - = operator.


objD -= obj.Add;
objD -= obj.Subtract;
POINTERS:

C#.NET supports pointers which are introduced from .NET frame work 2.0
version.

The code written used pointers in .NET is known as unsafe code because CLR
does not provide any security features and automatic memory management to the
code.

Pointers code must be enclosed with in unsafe block.

The code written by pointers must be compiled used unsafe option.

Declaration of a pointer variable in C#.net is known as shown below.


int *x //Not allowed
int* x x is a pointer variable which stores the address of integer variable
string* s s is a pointer variable which stores the address of string variable
float* f f is a pointer variable which stores the address of float variable
int** a a is a pointer variable. It stores address of another pointer variable
10
AB101F
int a = 10;
int* x;

68

Karthikeya

hanu.andru@yahoo.com

9052044478

x = & a;
x AB101F
*x 10
Example:

Namespace CApointers
{
class clsPointers1
{
unsafe static void Main ()
{
int a = 10;
int* x;
x = &a;
Console.WriteLine (Address of a + (int) x);
Console.WriteLine (Value of a is + *x);
Console.ReadLine ();
}
}
}

NOTE: - Unsafe block can be written also as below


unsafe
{
int a = 10;
int* x;
x = &a;
Console.WriteLine (Address of a + (int) x);
Console.WriteLine (Value of a is + *x);
Console.ReadLine ();
}

Simply include the above lines in our above example. It is same as used unsafe
before Main ()

The code written by used pointer. It must be compiled used unsafe option.
HOW TO COMPILE UNSAFE CODE:
1.
2.
3.
4.

Go to visual studio command prompt


change location to your file location
type CSC filename.cs / unsafe then press enter
retype filename.exe press enter

Example:

69

Karthikeya

hanu.andru@yahoo.com

9052044478

Namespace CApointers
{
class clsPointers2
{
unsafe static void cube (int *x)
{
int r = *x * *x * *x;
Console.WriteLine (Cube Value is + r);
}
static void Main ()
{
int a;
Console.WriteLine (Enter any number);
a = Convert. To int 32 (Console.ReadLine ());
unsafe
{
cube (&a);
}
Console.ReadLine ();
}
}
}

NOTE:

If most of the code contains pointers. We can use unsafe before class name

Then the total class is considered as it containing unsafe code.


SEALED CLASS:

A sealed class is a class which can not be derive further

To derive or declare a sealed class use sealed keyword

A sealed class can not contain abstract methods

A sealed class must be instantiated compulsory in order to consume it

A function also can be declared as sealed which is called as sealed function

A sealed function cant be overridden in any of the derived classes

If you want to create sealed method then it should have abstract or virtual
method in one of its Base class
Example:
clsEmployee
int Empid;
string Ename;

70

Karthikeya

hanu.andru@yahoo.com

9052044478

clsManager (sealed)
int Bonus;
Void GetEmpdata ();
Void DisplayEmpdata ();

Namespace CAsealed
{
class clsEmployee
{
protected int Empid;
protected string Ename;
}
sealed class clsManager : clsEmployee
{
int Bonus;
public void GetEmpdata ()
{
Console.WriteLine (Enter Manager id, name and Bonus);
Empid = Convert.Toint32 (Console.ReadLine( ));
Ename = Console.ReadLine();
Bonus = Convert.Toint32 (Console.ReadLine( ));
}
public void DisplayEmpdata()
{
Console.WriteLine (Manager Id is + Empid);
Console.WriteLine (Manager name is + Ename);
Console.WriteLine (Manager Bonus is + Bonus);
}
}
class clsSealed
{
static void Main ()
{
clsManager obj = new clsManager ( );
obj.GetEmpdata ();
obj.DisplayEmpdata ();
Console.ReadLine ();
}
}
}

ENUMERATIONS:

Enumerations are used to assign fixed values to some group of options like...

71

Karthikeya

hanu.andru@yahoo.com

9052044478

Example 1: -

Example 2: -

Weekdays

Performance

Sunday = 0;
Very poor = 0;
Monday = 1;
Poor = 1;
Tuesday = 2;
Average = 2;
Wednesday = 3;
Good = 3;
Thursday = 4;
Better = 4;
Friday = 5;
Best = 5;
Saturday = 6;
Excellent = 6;

To create an Enumeration we use enum keyword

To assign default values by incrementing 1, we declare our enumeration like...


enum Weekdays
{
Sunday, Monday, Tuesday, Wednesday, Thursday, Friday,
Saturday
}

To start assigning values other than 0, we use enumeration like


enum Weekdays
{
Sunday=45, Monday, Tuesday, Wednesday, Thursday, Friday,
Saturday
}

To assign different values for each option we create enumeration like below
enum Weekdays
{
Sunday=25, Monday=46, Tuesday=78, Wednesday=57,
Thursday=43, Friday=87
}
NOTE:

An enumeration type is a value type. Enumeration variables live on the stack

Internally an enum associates an integer value with each element. By default


the numbering starts at 0 for the first elements and goes up in steps of 1.
ACCESSING ENUMERATION MEMBERS:
SYNTAX:
enumeration name. Member name
Ex: -

Weekdays. Sunday = 10
Weekdays. Wednesday = 40 etc.
Namespace CAenumeration
{
72

Karthikeya

hanu.andru@yahoo.com

9052044478

class clsEnumeration
{
enum performance
{
Verypoor, Poor, Average, Good, Better, Best, Excellent;
}
static void Main ()
{
int v1, v2, v3, v4, v5, v6, v7;
v1 = Convert. To int32 (performance. Verypoor);
v2 = Convert. To int32 (performance. Poor);
v3 = Convert. To int32 (performance. Average);
v4 = Convert. To int32 (performance. Good);
v5 = Convert. To int32 (performance. Better);
v6 = Convert. To int32 (performance. Best);
v7 = Convert. To int32 (performance. Excellent);
Console. WriteLine (Value of very poor is + v1);
Console. WriteLine (Value of poor is + v2);
Console. WriteLine (Value of Average is + v3);
Console. WriteLine (Value of Good is + v4);
Console. WriteLine (Value of Better is + v5);
Console. WriteLine (Value of Best is + v6);
Console. WriteLine (Value of Excellent is + v7);
Console. ReadLine ();
}
}
}
GENERICS:

Generics are referred as General data type


Generic notation is represented used 2 values
* Data type parameter
* Place holder
Generics can be implemented for classes, interfaces, delegates, structures

DATA TYPE PARAMETER:

Any variable name can be used as data type parameter

PLACE HOLDER:

Generic notation is represented by the data type parameter with in the place
holder
SYNTAX:

73

Karthikeya

hanu.andru@yahoo.com
< DATA TYPE PARAMETER>

Ex: - A function with out generics


public void display (string s)
{
}
display (Hello..); // it is allowed
display (10); // it is not allowed
Ex: - A generic function
public void display <TP> <TP s>
{
}
display <string> (Hello...); // it is allowed
display <int> (10); // it is allowed
display <float> (10.5) // it is allowed
Example:
Namespace CaGenerics
{
class clsGeneric
{
static void Display< DTP > (DTP s)
{
Console.WriteLine(s);
}
static void Main()
{
Display< string > (sri ram);
Display< int > (4);
Display< double > (10.5);
Console.Read();
}
}
}
Example:
Namespace CaGenerics
{
class clsSample<DTP>
{

74

9052044478

Karthikeya

hanu.andru@yahoo.com

9052044478

public void swap (DTP a, DTP b)


{
Console.WriteLine(values before swaping..);
Console.WriteLine(values are {0}{1}..,a,b);
DTP c=a;
a=b; b=c;
Console.WriteLine(values after swaping..);
Console.WriteLine(values are {0}{1}..,a,b);
}
}
class clsGeneric
{
static void Main()
{
clsSample < string > objs =new clsSample();
objs.swap(hello,Good morning);
clsSample < int > obji =new clsSample();
obji.swap(10,20);
clsSample < double > objd =new clsSample();
objd.swap(10.5, 26.2);
Console.Read();
}
}
}
Exception Handling:
Any programming language contains 3 categories of errors:
1.
syntactical errors
2.
compilation errors
3.
logical errors
SYNTACTICAL ERRORS:
These errors occur when typing wrong syntax like missing terminator, typing wrong
spelling or missing parentheses etc.
In vs.net these errors are identified while writing the code because vs.net environment
has line interpreter
These errors are rectified by the programmer while writing the code
COMPILATION ERRORS:
These errors will occur when the programmer try to compile
I. These errors are like
Int a;
a=welcome;
i.e. assigning wrong values to the variables

75

Karthikeya

hanu.andru@yahoo.com

9052044478

II. creating an object for abstract class


III. including abstract functions in non abstract class
IV. trying to inherit a sealed class
These errors are identified by the compiler while compiling code or application
LOGICAL / RUN TIME ERRORS:
These errors occur while running of the application
When any runtime error occurs program execution will be stopped and application
will be terminated
But this should not happen while running application
Ex:
1.
2.
3.
4.

divided by zero error


index / argument out of range error
format error (giving wrong input)
access denied error

EXCEPTION:
A runtime error is known as an exception
(Or)
The errors that occurs during the execution of the program is known as exception
These are different methods available to handle the exception
1.
logical implementation
2.
on error go to method
3.
try-catch implementation
in the above program we get an error when user enters zero for b value
this can be handled logically as shown below
the code should be modified as above in example
it is not possible to handle all types of errors used logical implementation
when ever it is not possible to handle the error by logical implementation we use try
catch method used try catch method any type of error can be handled
SYNTAX:
Try
{
statements
..
..
}
catch ( Exception ex)
{
statements
..
..

76

Karthikeya

hanu.andru@yahoo.com

9052044478

}
finally
{
statements
..
..
}
TRY BLOCK:
All the statements in which there is possibility of error occurrence will be written with
in the try block
CATCH BLOCK:
When ever any error occurs to handle that error required statements are written with
in catch block
FIALLY BLOCK:
When error occurs or not if you want to execute some statements compulsorily those
statements put in finally block
Finally block is optional
Catch block is compulsorily i.e. one or more catch blocks are mandatory
Arguments of the catch block are optional
A try block can be nested with in a try block or with in a catch block
Ex:
If you want to display relevant message to the user about the error occurred in your
program then catch block is written as follow
Catch (Exception ex)
{
Conloe.WriteLine (ex.Message);
}
to handle the exceptions in .net msoft designed various exception classes like
DIVIDED BY ZERO EXCEPTION:
This class will handle the exception that is occurred by dividing with zero only
ARITHEMETIC EXCEPTION CLASS:
This exception class will handle all the exceptions that will occur due to arithmetic
operators
FORMAT EXCEPTION CLASS:
This class will handle the exception that occur by assigning wrong format values to
the variables

77

Karthikeya

hanu.andru@yahoo.com

9052044478

EXCEPTION:
This class will handle all categories of exception
When we write the exception used catch block always use the hierarchy of exceptions
because first compiler will search in relevant exception class and then goes to next
relevant
Ex:
PROPERTIES OF EXCEPTION OBJ:
Message:
This property stores descriptive reason about why error has been occurred
Source:
This property stores the name of the application from which error has been raised
Help Link:
This property is used to set or get the link to help file that you want to redirect the
user when error occurs

WINDOWS APPLICATION

* Windows applications will provide GUI facilities


* used this we can create desktop as well as client server applications
* by default a from appears on the screen
* a form is a container which holds the other controls like textbox, label, button etc
* in .NET a form is a class which is inherited or derived from
system.windows.forms.formclass
* windows applications are created used IDE environment
* IDE contains the following important components
1. Solution Explorer (ctrl+alt+L)
2. ToolBox
(ctrl+alt+x)
3. Properties window (F4)
4. Server Explorer (ctrl+alt+s)
SOLUTION EXPLORER:
* this contains the application and related files of the application
* used this we can add both new files and existing files
* we can add new files/folders

78

Karthikeya

hanu.andru@yahoo.com

9052044478

* we can add existing files/folders


* we can rename files/folders
* we can copy files/folders
* we can move files/folders
* we can delete files/folders
* solution explorer can work similar to windows explorer
TOOL BOX:
* tool box contains various tool tabs
* each tool tab contains different controls like textbox, button, label etc..
* used the tool box we can create any required control by double clicking on the
control with out writing any code
* vs.net environment will generate required code for the controls
* in .net every control has a separate class
ex:
textbox
system.windows.forms.textbox
button
system.windows.forms.button
label
system.windows.forms.label
* whatever the controls we create used toolbox they are the objects of respective
class
PROPERTIES:
* this window allow to set values to the properties and events of the required object
SERVER EXPLORER:
* This is used to connect to required data base and access the database objects like
tables, views, stored procedures etc
EVENTS:
* events are members of a class used to perform some sort of action
* every event will be raised when it is called
* events may not occur always suppose the event eating will not occur always. Only
when we are hungry then the event eating is invoked
* similarly respective events in windows are also invoked in need
LIST OF CONTROLS:
TEXT BOX:
This control is used to accept the data from the user and also to display data to the
user
Properties:

79

Karthikeya
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.

hanu.andru@yahoo.com

9052044478

Name
back color
(default is white)
border style (none, fixed single, fixed 3d*)
character casing
(normal*, lower, upper)
dock
(top, left, bottom, right, fill, none*)
enabled
(true*, false)
font
location
(x-left, y-right)
fore color
(default is black)
located
(true, false*)
max length (32767*)
multi line
(true, false*)
password char
size
(height, width)
tab index
text
text align
(left*, center, right)
visible
(true*, false)

NAME:
* is the programmatic reference of the control
* this is an object name for the respective class
BACK CLOLR:
* used to set or get back ground color of text box
BORDER STYLE:
* used to set or get border of the text box
* when set to none text box contains no border
* when set to fixed single text box contains single border
* when it set to fixed 3d text box will get 3 dimensional border
CHARACTER CASING:
* When it set to lower contents of text box will appear in lower case letters
* when it set to upper contents of text box will appear in upper case letters
* when it set to normal contents of text box will appear in the case how we typed
DOCK:
* used to set or get the text box at required location
ENABLED:
* when it set to true user can access the control at runtime
* when it set to false user can not access the control at runtime
FONT:
* used to set or get font attributes like font name, font size, font style etc
FORE COLOR:
* used to set color of the text..
LOCATION:
* used to arrange the text box at required position from the left and top borders of the
form
LOCKED:

80

Karthikeya

hanu.andru@yahoo.com

9052044478

* when it set to true it is not possible to change the location of the control
MAX LENGTH:
* used to restrict the user to enter max number of characters
* when max length is set to zero(0) you can store
2 gb for single line text box
4 gb for multi line text box
MULTI LINE:
* when it set to true contents of text box will appear in more than one line
* when it set to false contents of text box will appear in single line
PASSWORD CHAR:
* used to set any character to appear in the place of original text
* any single character or space can be set as pass word char
* it is no possible to set more than one character
* password char will work when multi line is set to false
SIZE:
* used to increase or decrease height and width of text box
* when multi line is false height is scaled to font size i.e. we can not increase or
decrease height of text box
* when multi line is true we can increase or decrease the height of text box
TAB INDEX:
* Used to set the order of focus entry when user presses tab key at runtime
* by default first created control tab index is zero
* next created control tab index incremented by 1
TEXT:
* used to set or get contents of text box control
TEXT ALIGNS:
* when it set to left contents of text box are display from left side
* when it set to right contents of text box are display from right side
* when it set to center contents of text box are display from center side
VISIBLE:
* when it set to false control appears at design time but does not appear at runtime
Events:
5.
6.
7.
8.
9.

text changed*
leave
enter
click
keypress

TEXT CHANGED:
* this event is fired when contents of text box control are changed
LEAVE:
* this event is fired when focus leaves from the text box
ENTER:
* this event is raised when focus enters in to the text box

81

Karthikeya

hanu.andru@yahoo.com

9052044478

CLICK:
* this event is raised when user clicks on the text box with mouse
KEYPRESS:
* this event is raised when user press any key from the key board with in the text box
BUGS / VALIDATIONS:
1.
2.
value in txtnum1
3.
4.

txtnum1 should accept only digits


txtnum2 should accept only digitsBangaru..

user must enter any

user must enter any value in txtnum2


txtnum2 should not be zero for division

KEY PRESS EVENT:


* this event is invoked when user press any key from the key board. This event has 2
arguments
1. Object Sender
2. KeypressEventArgs e
OBJECT SENDER:
* sender is an object to object class it stores the type of object from which controls
event has been raised
KEYPRESS EVENT ARGS E:
* e is an object to keypresseventargs class. It has two imp properties
1. key char
2. handled property
KEY CHAR:
* this property stores the value of the character that is pressed by the user with in the
text box
HANDLED PROPERTY:
* this is a Boolean value property default value is false
* if handled is false pressed character appears in the text box
* if handled is true pressed character does not appear in the text box
CHAR CLASS:
* this class provides various methods to work with a character
1. is digit();
2. is letter();
3. is upper();
4. is lower();
5. is symbol();
6. to lower();
7. to upper();
IS DIGIT:

82

Karthikeya

hanu.andru@yahoo.com

9052044478

* this method takes a character as an argument and returns true if the character is
digit; other wise returns false
ex:
Is Digit (A) false
Is Digit (9) true
IS LETTER:
* this method takes a character as an argument and returns true if the character is an
alphabet other wise it returns false
ex:
Is Letter (A) true
Is Letter (9) false
IS UPPER:
* this method takes a character as an argument and returns true if the character is in
upper case; other wise it returns false
ex:
Is Upper (A) true
Is Upper (9) false
Is Upper (a) false
IS LOWER:
* this method takes a character as an argument and returns true if the character is in
lower case; other wise it returns false
ex:
Is Lower (A) false
Is Lower (9) false
Is Lower (a) true
IS SYMBOL:
* this method takes a character as an argument and returns true if the character is a
special symbol; other wise it returns false
ex:
Is Symbol (<) true
Is Symbol (.) true
Is Symbol (a) false
TO LOWER:
* this method takes a character as an argument and converts it into lower case
ex:
To Lower (A) a
TO UPPER:
* this method takes a character as an argument and converts it into upper case
ex:
To Upper (a) A
CODE:
If( char. Is Digit(e.key char)==false)
{
MessageBox.Show(Enter Digits only);
e.Handled= true;

83

Karthikeya

hanu.andru@yahoo.com

9052044478

}
* Above is little bit costlier than normal logical Implementation
* handling the error used try-catch is costlier in time as compared to logical
implementation
* So first try to handle the errors or validation used logical implementation
* If it is not possible to handle with logical implementations then go for try-catch
implementation

LABEL CONTROL:
Label control is used to give description to the other controls or used to display static
message
HOT KEYS:
File, Edit, View, Project here F, E, V and P are hot keys
Used simply Alt+F we can go to file menu
Assigning Hot keys to the controls:
To assign the Hotkey to any control
* select the control
* go to the property
* type & symbol before the character for which you want to assign Hot
key...
RADIO BUTTON:
Radio button is used to provide selection of only one option from the group of options
i.e. user can select only one radio button from the group of radio buttons
Properties:
1.
2.
3.
4.
Auto size:

Auto size (True*, False)


Check Align ()
Text Align ()
Checked (True, False*)

When set to true, width of the radio button is scaled to text property and height is
scaled to font property.
When set to false, we can increase or decrease the width and height of radio button.
Text Align:

84

Karthikeya

hanu.andru@yahoo.com

9052044478

This property is used to set the position of the text with in the radio button control.
Check Align:
This property is used to set the position of circle with in the radio button positions are
shown in Fig1.
Checked:
This property stores True when radio button is selected and stores False when radio
button is deselected.
Default event of radio button is Checked Changed Event.
This event is raised when checked property of a radio button changes from false to
true.
Grouping Controls:
These controls are used to group the other controls together.
Types of grouping controls:
1.
Group Box Control
2.
Panel Control
3.
Tab Control
1.
2.
3.
4.

Group Box
Has text area
Does not provide scrolling
capabilities
occupies more design space
occupies less memory

Panel
Has no text Area
provides scrolling capabilities
occupies less design space
occupies more memory

Check Box:
This control is used to provide selection of more than one option from the given set of
options
Properties and events of check box control are similar to radio button control.
Code:
String s = txtName.Text + Hobbies are..;
Foreach (control ctrl in this.controls)
{
if (control is checkbox)
{
check Box c1= (checkBox) ctrl;
if (c1.checked == true)
{

85

Karthikeya

hanu.andru@yahoo.com

9052044478

s=s+c1.text;
}
}
}
lblDisplay.Text=s;
LIST BOX:
A list box control is used to display group of options to the user so that user can select
one item or group of items randomly or range of items.
Properties:
1.
2.
3.

Items collection
selection mode (single*, multi simple, multi extended, none)
sorted (true, false*)

Properties at runtime only:


1.
2.
3.
4.

selected index
selected item
selected indices
selected items

properties with items collection:


1. count
methods with items collection:
1.
2.
3.
4.
5.

add (object item)


insert (int index, object item)
remove (object name)
remove at (int index)
clear ()
Array

Collection

1.
Array size is fixed
2.
Array supports only single data types
3.
when a new element is inserted, existing element is over written
4.
Array existing element can not be deleted directly
1.
collection size is not fixed
2.
collection supports multiple data types
3.
when a new element is inserted, existing element will not be over written
rather the elements will flush down

86

Karthikeya

hanu.andru@yahoo.com

9052044478

4.
when an existing element is deleted following element will flush up
automatically
Items:
Items is the collection property with list box used to set or get the elements or items of
list box
Selection mode:
When set to single, user can select only one item from the list box control
When set to multi simple user can select group of items randomly
When set to multi extended user can select range of items
When set to none user can not select any item
Sort:
When set to true, items will be arranged in alphabetical order
Selected index:
Used to set or get the index value of the item selected by the user at runtime
Ex:
lstCourse.selectedIndex 1
lstCourse.selectedItem C++
selected item:
used to set or get the item that is selected by user at runtime
selected indices:
used to set or get the index values of the selected items by the user at runtime
selected indices are stored in the form of collection
selected items:
used to set or get the list of items that are selected by user at runtime
count property:
this property returns the count of items present in the list box items collection
methods with items collection:
Add (object item):

87

Karthikeya

hanu.andru@yahoo.com

9052044478

This method is used to add a new item to the list box items collection
By default the item will be added at the end of the collection provided sorted is false
Ex:
Insert (int index, object name):
This method is used to add a new item at the required location in to the list box
collection
Item is added in the specified location when sorted is false
If sorted is true item will be added in its alphabetical order location
Remove (object name):
This method is used to remove any item used its object value from the list box item
collection
RemoveAt (int index):
This method is used to delete any item from the list box items collection used its index
value
Clear ():
This method is used to delete all the items from the list box control

default event of list box control is selected index changed event


this event is fired when user selects any item with in the list box control

Validations for add button:


1.
txtItem should not be empty
2.
duplicate values should not be added
validations for Insert button:
1.
txtItem should not be empty
2.
duplicate values should not be added
3.
txtIndex shoul not be empty
4.
Index value should be o to count only
5.
txtIndex should be integer
validations for remove button:
1. entered item in txtItem text box must be present in lstCourse
validations for remove at :
1.
txtIndex should not be empty
2.
index value should be between 0 to count-1
COMBO BOX:
Combo box is the combination of both text box and list box control
In text box, it is not possible to display group of items, but user can type any text

88

Karthikeya

hanu.andru@yahoo.com

9052044478

In list box control, we can display group of items but user can not type any text in the
list box control
In combo box, we can display group of items so that user can select any item and user
can type any text in to the combo box at runtime.
Properties:
1.
drop down style (simple, dropdown*, dropdownlist)
2.
items (collection)
3.
maxdropdownitems (8*)
4.
sorted (true, false*)
DROP DOWN STYLE:
Simple:
Appearance of the combobox changes as combination of textbox and list box
User can select any item and user can type any text
Dropdown:
Appears as combobox only, user can select any item and also user can type any
text
Dropdown list:
Appears as combobox only, user can select any item but user cant type any
text
Note:
Other properties like selected item, selected index etc.. are same as list box
control. Default event of combo box is selected index changed event
PICTURE BOX:
This control is used to display any image to the user. Images can be displayed like
jpeg, bmp, giff, ico
Jpeg: joint pictures export group
Giff: graphic image file format
Bmp: bitmap file
Ico: icon file
Properties:
1.
2.
3.

image
image location
size mode ( normal, stretch image, auto size, center image)

image:
this property is used to attach any image to the picture box control
generally we can attach the images that are available in local application only

89

Karthikeya

hanu.andru@yahoo.com

9052044478

when we attach any file which is not in local app. Then a copy of the image file will be
made into local app.
Image location:
This property is used to attach any image to the picture box control from the disk
location directly
Size mode:
Normal:
when set to normal, image and picture boxes will have their own sizes.
Picture boxes will have their own sizes. Image size will not increased or decreased
when picture box size is increased or decreased
Stretch image:
Image size is scaled to picture box size when picture box size is increased,
image size is increased and when picture box size is decreased, image size is
decreased.
Auto size:
Picture box size is scaled to image size. We cant increase or decrease picture
box size
Center image:
Image is displayed with in the center location of picture box.
Code:
Private void cmdLoad_click()
{
picturebox1.Image = Image.fromFile (E:\\as.bmp);
}
Private void cmdLoad_click()
{
picturebox1.Imagelocation = E:\\as.bmp;
}
Timer:
This control is used to execute the required code repeatedly after every set
internal period of time
This is only control in complete .net which doesnt require any user intervention to
execute the code
Properties:

90

Karthikeya

1.
2.

hanu.andru@yahoo.com

9052044478

enabled (true, false*)


internal (100*)

Enabled:
When set to true, timer starts functioning when set to false timer stops
functioning
Interval:
Used to set the required time period after which we would like to execute the
code repeatedly
Tick event:
This is the only event, timer control has. This event is raised repeatedly after
set interval period of time
Component tray:
The controls that appear at design time but dont appear at runtime are
placed with in the component tray
Code:
Timer (enabled=true, internal=500)
Static int i=0;
Private void timer1_tick ()
{
if ( i==0)
{
lblSample1.Text = hello;
lblSample1.BackColor = Color.green;
i=1;
}
else
{
lblSample1.Text = Hyderabad;
lblSample1.BackColor = Color.Red;
i=0;
}
}
Image List:
This control is used to store group of images with in it and the stored images can be
attached to any other controls like:
Picture box
Tool bar

91

Karthikeya

hanu.andru@yahoo.com

9052044478

Menus etc
Properties:
1.
color depth (depth 4 bit, 8 bit*, 16 bit, 24 bit, 32 bit)
2.
images (collection)
3.
image size (16, 16*)(256, 256)
Color depth:
This property is used to set intensity of colors
The more the intensity of colors, the more will be the clarity of picture
Images:
This is a collection property which stores all the list of images
Each image is identified used its index value
Image size:
This property is used to set or get the size of image that we want to store with in the
image list control
Code:
Static int i=0;
Private void timer1_tick ()
{
pictureBox1.Image=Imagelist1.Images[i];
if ( i==Imagelist1.Images.count)
{
i=0; // timer1.enable==false;
}
}
Dialog controls:
Dialog controls are used to perform some common actions like
1.
opening a file
2.
saving a file
3.
applying font attributes and colors
4.
performing page settings
5.
printing a document etc
TYPES OF COMMON DIALOG CONTROLS:
1.
open file dialog control
2.
save file dialog control
3.
font dialog control
4.
color dialog control
5.
page setup dialog control
6.
print dialog control
Open file dialog control:

92

Karthikeya

hanu.andru@yahoo.com

9052044478

This control is used to display open file dialog box to the user so that user can select
any file to open
a.
file name
b.
filter
File name:
This property is used to set or get name of the file selected by user at runtime
Filter:
This property is used to filter the category of files to display to the user like word files,
XL files, notepad files etc
Save file dialog control:
This control is used to display save as dialog box to the user so that user can enter any
file name to save
a.
file name
b.
filter
Filename:
This property is used to set or get the filename selected by the user in Save File Dialog
Control.
Filter:
This property is used to FILTER the files for saving like Wordfiles,XL files,Text
files,ALL files etc.
FontDialogControl:
This property is used to display Font Dialog Box to the user so that the user can select
the required Font attributes to apply for the required Text.
Poperties:
i>Font
ii>MaxSize
iii>MinSize
iv>ShowEffect (true*, false)
Font:
This property is used to set or get font attributes with in the font dialog box at run
time
Maxsize:
This property is used to set or get max font size with in the font dialog box so that to
display to the user
Minsize:
This property is used to set or get minimum font size that is required to be displayed
to the user with in the font dialog box

93

Karthikeya

hanu.andru@yahoo.com

9052044478

Show effects:
When set to true, user can access show effects option in font dialog control
When set to false, user cant access that option with in font dialog control
COLOR DIALOG CONTROL:
This control is used to display color dialog box to the user so that user can select
required color to apply for required settings
Properties:
1.
color
2.
allow full open (true*, false)
3.
full open (true, false*)
Color:
This property is used to set or get the color value that is selected by the user in
color dialog control
Allow full open:
When set to true, user can access define custom colors button with in the
color dialog control. Other wise user cant access Define custom color button in
color dialog control
Full open:
When set to true, the color dialog box will be opened in full mode. Other wise
color dialog box will be opened in partial mode
PAGE SETUP DIALOG CONTROL:
This control is used to display page setup dialog box to the user so that user
can set the required page settings for the document
Property:
1. Document
Document:
This property is used to set the print document for which user would like to
print
PRINT DIALOG CONTROL:
This control is used to display print dialog box so that user can print the
required file
Property:
1. Document
Document:

94

Karthikeya

hanu.andru@yahoo.com

9052044478

This property is used to set the print document for which user would like to
print
METHOD:
Show dialog:
This method is used to display any dialog control to the user
Used filter property:
openFileDialog1.Filter=Filter Expression;
separate both parts used | (pipe) symbol
ex:
openFileDilog1.File=TextFiles|*.txt|word documents|*.doc|All files|
*.*
Code:
Private void cmdFont_Click ()
{
FontDialog1.ShowDiolog();
txtName.Font=FontDialog1.Font;
}
Private void cmdColor_Click ()
{
ColorDialog1.ShowDiolog();
txtName.ForeColor=FontDialog1.Color;
}
Creating Menus:
Any windows based application will have 2 types of menus
1.
main menu
2.
context or short cut menu
to create main menu use menu strip control
to crate context menu, use context menu strip control

CONTEXT MENU:
A context menu is also known as short cut menu
Creating short cut menu is similar to main menu
Attaching context menu to required control:

95

Karthikeya

hanu.andru@yahoo.com

9052044478

Select the text box


Go to context menu strip property
Select context menu strip1 (from the list of options available)
CREATING MDI APPLICATIONS:
PROGRESS BAR CONTROL:
This control is used to display progress of any application
Properties:
1.
2.
3.
4.

maximum (100*)
minimum (0*)
step (10*)
value

Maximum:
This property is used to set the end value where progress bar control should stop its
execution
Minimum:
This property is used to represent from where the progress bar should start its
execution
Step:
This property value represents how much we want to increment the progress bar
value at each time
Value:
This property indicates or stores the current position of two progress bar control
Code:
Private void Timer_Click ()
{
progressBar1.value = progressBar1.value + ProgressBar1.step;
if (ProgressBar1.value >= ProgressBar1.Maximum)
{
Timer1.Enabled = false;
}
if (i==0)
{
lblDisplay.Text= Please wait;
}
else

96

Karthikeya

hanu.andru@yahoo.com

9052044478

{
lblDisplay.Text = ;
i=0;
}
}
SPINNER / NUMERIC UP DOWN CONTROL:
This control is used to provide increment or decrement of values
Properties:
1.
2.
3.
4.
5.

Maximum (100*)
Minimum (0*)
value
increment (1*)
up down align (left, right*)

Maximum:
This property is used to set maximum value where spinner control should stop its
increment
Minimum:
This property indicates a value where spinner control should stop its decrement
Value:
This property stores the current value present in the spinner control
Increment:
This property indicates how much value is to be incremented or decrement when user
clicks on up arrow or down arrow of the numeric up down control
Up down align:
This property indicates the alignment of up down button with in the spinner control
Default event of spinner control is value changed event
DATE TIME PICKER CONTROL:
This control is used to display calendar to the user so that user can select required
date from the control
Properties:
1.
2.

mindate (01/01/1753*)
maxdate (31/12/9998*)

97

Karthikeya
3.
4.
5.

hanu.andru@yahoo.com

9052044478

value
format (time, long*, short, custom)
custom format

Mindate:
This property is used to set minimum date that user can select with in the date time
picker control
Maxdate:
This property is used to set the maximum date that user can select with in the date
time picker control
Value:
This property stores the current date value selected by the user with in the date time
picker control
Format:
This property is used to set the required format for the date time picker control
Custom format:
This property is used to set user defined format value for date time picker control
when format property is set to custom
Default event of date time picker control is value changed event
TOOL TIP CONTROL:
This control is used to display some tip information when user places mouse pointer
on any control
A single tool tip can be attached to any no of controls
NOTIFY ICON CONTROL:
This control is used to display any icon symbol with in the system tray when
application starts running
TREE VIEW CONTROL:
This control is used to display group of options in hierarchical manner
Used in real time applications
Institutions
Peers
.net
Java
Oracle
Ajax
Satya

98

Karthikeya

hanu.andru@yahoo.com

9052044478

Properties:
1.
Nodes (collection)
2.
Show plus minus (true*, false)
3.
show Lines (true*, false)
4.
selected node (available at runtime)
Default event of tree view control is after select
Nodes:
Nodes is the collection property of tree view control which is used to get or set
the required nodes with in the tree view control
Identifications:
tvSample.Nodes

Peers
Satya
Naresh
tvSample.Nodes[0] Peers
tvSample.Nodes[0].Nodes

.Net
Java
Ajax
tvSample.Nodes[0].Nodes[0] .Net
Adding Nodes at runtime:
tvSample.Nodes.Add(Peers);
tvSample.Nodes.Add(Satya);
tvSample.Nodes.Add(Naresh);
tvSample.Nodes[0].Nodes.Add(.Net);
RICH TEXT BOX:
This control is used to display the dynamic data to the user and accepts input
from the user
As compared to text box, rich text box will provide additional properties and
methods and it accepts additional data i.e. more no of characters as compared to text
box
Methods:
1.
2.
3.
4.
5.
6.
7.
8.

Clear ()
Copy ()
Cut ()
Find (search string)
Load file (file path, Rich Text Box stream type)
Paste ()
Save File (file path, Rich Text Box Stream type)
Select All ()

99

Karthikeya
9.

hanu.andru@yahoo.com

9052044478

Undo ()

Properties:
1.
2.
3.

Selected Text
Text Length
Word wrap (true*, false)

Methods:
Clear:
This method is used to delete the complete contents of rich text box control
Copy:
This method is used to copy the selected contents from rich text box and place
in clip board
Cut:
This method is used to delete the selected content from rich text box and place
in clip board
Clip board:
We can see this clip board VS2005ImageLibrary/bitmaps/misc
Find:
This method is used to find existence of a string with in the rich text box text.
If search string is found this method will return positive value either it is equal to zero
or more than zero
If search string is not found this method will return a value that is negative
Load file:
This method is used to load the contents of a selected file in to rich text box
control
Paste:
This method is used to paste the contents of the clip board in to the rich text
box control
Save file:
This method is used to save contents of rich text box in to local system
Select All:
This method is used to select all the content of rich text box control
Undo:
This method is used to cancel the previous action that has been made with rich
text box control

100

Karthikeya

hanu.andru@yahoo.com

9052044478

Selected text:
This property will return the value of selected contents by the user at runtime
Text Length:
This property will return the no of characters present in rich text box control
Word wrap:
When it set to true, the text in the control appears in more than one line.
Otherwise the text will appear in single line
Note:
Expect password char property all other properties in text box are available in
rich text box control.
String. Last Index Of:
To display just file name in the place of untitled note pad when you open any
file.
Private void smnu_Click(---)
{
rtbNotepad.Clear();
This.Text = Untitled NotePad;
}
Private void smnuOpen_Click(---)
{
OpenFileDialog1.Filter = ;
OpenFileDialog1.ShowDialog ();
rtbNotepad.Load file (OpenFileDialog1.FileName,
richTextBoxStreamType.PlainText);
this.Text = OpenFileDialog1.FileName;
}
Private void smnuSaveAs_Click(---)
{
SaveFileDialog1.Filter = ;
SaveFileDialog1.ShowDialog ();
rtbNotepad.Savefile (SaveFileDialog1.FileName,
richTextBoxStreamType.PlainText);
this.Text = OpenFileDialog1.FileName;
}
private void smnuSave_Click(---)
{

101

Karthikeya

hanu.andru@yahoo.com

9052044478

if (this.Text == Untitled-NotePad)
{
smnuSaveAs_Click (sender, e);
}
else
{
rtbNotepad.SaveFile (This.Text, RichTextBoxStreamType.PlainText);
}
}
Private void smnuWordWrap_Click(---)
{
if (smnuWordWrap.Checked==true)
{
smnuWordWrap.Checked = false;
rtbNotePad.WordWrap = false;
}
else
{
smnuWordWrap.Checked = true;
rtbNotePad.WordWrap = true;
}
}
Note: Color changes and font changes are not applied permanently
Micro Soft Visual Basic:
Is a name space which contains all properties and methods of visual basic and
can be used by c#
To accept any value from the user there is a function available in visual basic
(vb.net) known as
Input Box:

namespace of this function is Microsoft.Visual Basic

Class of this function is Interaction

Syntax of this function is


String s = Interaction.InputBox (Prompt, Title, Default value, X
position, Y position)
Steps:
In clued the namespace used microsoft.Visul Basic
Private void smnuFind_Click(---)
{

102

Karthikeya

hanu.andru@yahoo.com

9052044478

string s = Interaction.InputBox (Enter Search Value, Find, Hello, 100,


100);
int I = rtbNotePad.Find (s);
if (i>=0)
{
MessageBox.Show (string Found);
}
else
{
MessageBox.Show (string is not found);
}
}
Page Set up:
Page set up Dialog Box and print dialog box both accepts print document like
Page set up Dialpg1.Document = print document
Print document is a separate class which is available with in the name space
system.Drawing.Printing
To display page set up Dialog box use the following steps:
1. include or import the name space system.Drawing.Printing
used System.Drawing.Printing
2. create an object to print document class
print document p= new print document ()
3. set the document name for which you want to set page settings to print
document object
p.document name = give path here;
4. set the print document to page set Dialog box
pageSetupDialog1.Document = p;
5. Display the page Setup Dialog Box
pageSetupDialog1.ShowDialog ();
Program code: Page setup
Used system.Drawing.Printing;
Private void smnuPageSetup_click(---)
{
printDocument p = new printDocument ();
p. Document Name = This.Text;
Page Set up Dialog1.Document = p;
Page SetupDialog1.ShowDialog();
}

103

Karthikeya

hanu.andru@yahoo.com

9052044478

private void smnuPrint_Click(----)


{
printDocument p = new PrintDocument ();
p.Document Name = this.Text;
page set up Dialog1.Document = p;
PrintDialog1.ShowDialog();
}
validations:
cut, copy, paste should be disable when user has not selected any text
private void smnuEdit_Click(---)
{
if (rtbNotepad.SelectedText == )
{
smnuCut.Enabled = false;
smnuCopy.Enabled = false;
smnuDelete. Enabled = false;
}
else
{
smnuCut.Enabled = true;
smnuCopy.Enabled = true;
smnuDelete. Enabled = true;
}
}

104

TPYES OF ARRAYS:
Types Arrays

Based on physical size

Based on memory size


Special type

1. Single Dimensional Array


1. Normal Array
Array
Jogged Array
2. Multi Dimensional Array
2. Huge Array
Array

Based on size nature

1.

Static

2.

Dynamic

Вам также может понравиться