Академический Документы
Профессиональный Документы
Культура Документы
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 ();
}
}
}
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 ()
Karthikeya
hanu.andru@yahoo.com
9052044478
PROGRAMING CONSTRUCTS:
The methods we use to write a program are called programming constructs
Karthikeya
hanu.andru@yahoo.com
9052044478
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
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
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;
}
}
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
RESERVED KEYWORDS:
16
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
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
22
Karthikeya
hanu.andru@yahoo.com
9052044478
* 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
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
1
0
2
0
3
0
4
50
23
Karthikeya
hanu.andru@yahoo.com
9052044478
B
0
2
10
3
50
4
20
3
40
4
10
2
40
3
50
24
4
60
Karthikeya
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.
* 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:
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
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:
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
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
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
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
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
41
Karthikeya
hanu.andru@yahoo.com
9052044478
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
42
Karthikeya
hanu.andru@yahoo.com
9052044478
}
}
DISADVANTAGES:
If we create number of objects, same values are stored in to all object data
fields
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
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
46
Karthikeya
hanu.andru@yahoo.com
9052044478
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:
FUNCTION OVERLOADING:
Assigning additional work to an existing function other than the original work
is known as function overloading
47
Karthikeya
hanu.andru@yahoo.com
9052044478
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:
}
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:
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
While accepting the data of the Manager, it isnt required to accept Eage and
Eaddress
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:
NOTE:
A function which contains only declaration and does not contain any
functionality is known as abstract function
An abstract class can contain both abstract and non abstract functions
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:
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
1. overriding of abstract
methods in derived class is
compulsory
2. by default all members of
interface are public..
NOTE:
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)
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
Properties are used to provide data abstraction to the data fields of the class
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:
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
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:
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
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
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:
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:
Properties are used to a single data field, where as indexers are used to provide
data abstraction to multiple variables
}
}
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:
The signature of the delegate must be same as the signature of the function
that we want to represent.
Karthikeya
hanu.andru@yahoo.com
9052044478
}
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
Though a delegate maintains a pointer to the function, it will not follow unsafe
code.
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;
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.
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 ();
}
}
}
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.
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
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 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:
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:
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>
74
9052044478
Karthikeya
hanu.andru@yahoo.com
9052044478
75
Karthikeya
hanu.andru@yahoo.com
9052044478
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
78
Karthikeya
hanu.andru@yahoo.com
9052044478
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.
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:
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*)
selected index
selected item
selected indices
selected items
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
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:
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
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:
102
Karthikeya
hanu.andru@yahoo.com
9052044478
103
Karthikeya
hanu.andru@yahoo.com
9052044478
104
TPYES OF ARRAYS:
Types Arrays
1.
Static
2.
Dynamic