<ul><li>Generics </li></ul>
<ul><li>Generics are used to work with General Datatypes. </li></ul><ul><li>If we declare a variable with general notation...
<ul><li>To implement generics we use </li></ul><ul><li>1) Place Holder ‘<>’ </li></ul><ul><li>2) Type Parameter </li></ul>...
<ul><li>Examples: </li></ul><ul><li>Non-Generic Function: </li></ul><ul><li>public void Display(string s) </li></ul><ul><l...
<ul><li>Generic Function: </li></ul><ul><li>Public void Display<G>(G s) </li></ul><ul><li>{ </li></ul><ul><li>} </li></ul>...
<ul><li>Passing Multiple data types for a function we use the function as below </li></ul><ul><li>static void Display<G1,G...
<ul><li>A Delegate is similar to a class used to refer one or more functions. </li></ul><ul><li>To create delegate we will...
<ul><li>Single Cast Delegate : </li></ul><ul><li>A Delegate that refers only one function is known as Single-Cast Delegate...
<ul><li>ii) Instantiating the Delegate. </li></ul><ul><li>iii) Invoking the Delagate. </li></ul><ul><li>Creating a Delegat...
<ul><li>Invoking a Delegate : </li></ul><ul><li>Syntax: </li></ul><ul><li>DelegateobjectName(argslist); </li></ul><ul><li>...
<ul><li>http://www.akadia.com/services/dotnet_delegates_and_events.html </li></ul><ul><li>http://www.c-sharpcorner.com/Upl...
<ul><li>Thank You ! </li></ul>
Upcoming SlideShare
Loading in …5
×

Generics n delegates

926 views

Published on

Published in: Education
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
926
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
0
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Generics n delegates

  1. 1. <ul><li>Generics </li></ul>
  2. 2. <ul><li>Generics are used to work with General Datatypes. </li></ul><ul><li>If we declare a variable with general notation we can pass or store any data type value within that Generic Variable. </li></ul><ul><li>Generics are similar to Templates in C++. </li></ul><ul><li>Generics are used aviod Function overloading when data types of Arguments are changed. </li></ul>
  3. 3. <ul><li>To implement generics we use </li></ul><ul><li>1) Place Holder ‘<>’ </li></ul><ul><li>2) Type Parameter </li></ul><ul><li>If a function is implemented with Generic notation then it is called as ‘Generic Function’. </li></ul><ul><li>If a class is implemented with Generic notation then it is called as ‘Generic Class’ </li></ul>
  4. 4. <ul><li>Examples: </li></ul><ul><li>Non-Generic Function: </li></ul><ul><li>public void Display(string s) </li></ul><ul><li>{ </li></ul><ul><li>} </li></ul><ul><li>By using above function we can display only string values. </li></ul><ul><li>i.e Display(“Welcome”) </li></ul><ul><li>Display(10),Display(10.5) it is not possible. </li></ul>
  5. 5. <ul><li>Generic Function: </li></ul><ul><li>Public void Display<G>(G s) </li></ul><ul><li>{ </li></ul><ul><li>} </li></ul><ul><li>By using above Generic function we can display any value. </li></ul><ul><li>Like Display<string>(“Welcome”) </li></ul><ul><li>Display<int>(10) </li></ul><ul><li>Display<double>(10.5) </li></ul>
  6. 6. <ul><li>Passing Multiple data types for a function we use the function as below </li></ul><ul><li>static void Display<G1,G2>(G1 a,G2 b) </li></ul><ul><li>{ </li></ul><ul><li>} </li></ul><ul><li>Display<string,int>(“welcome”,10) </li></ul><ul><li>Display<double,string>(10.5,”Welcome”) </li></ul><ul><li>Display<int,int>(10,10) </li></ul>
  7. 7. <ul><li>A Delegate is similar to a class used to refer one or more functions. </li></ul><ul><li>To create delegate we will use ‘delegate’ Keyword. </li></ul><ul><li>C# supports two types of delegates. </li></ul><ul><li>1) Single cast Delegate </li></ul><ul><li>2) Multi-Cast Delegate </li></ul>
  8. 8. <ul><li>Single Cast Delegate : </li></ul><ul><li>A Delegate that refers only one function is known as Single-Cast Delegate. </li></ul><ul><li>Multi-Cast Delegate: </li></ul><ul><li>A delegate that refers two or more functions is known as Multi-Cast Delegate. </li></ul><ul><li>How to create Delegate: </li></ul><ul><li>To create a delegate we will use following steps </li></ul><ul><li>i) Creating a delegate </li></ul>
  9. 9. <ul><li>ii) Instantiating the Delegate. </li></ul><ul><li>iii) Invoking the Delagate. </li></ul><ul><li>Creating a Delegate: </li></ul><ul><li>Syntax: </li></ul><ul><li>Accessmodifier delegate returntype Delagatename(args list); </li></ul><ul><li>Ex: public delegate int D1(int a,int b); </li></ul><ul><li>Instantiating a Delegate : </li></ul><ul><li>DelegateName objname=new Delegatename(TargetFunname); </li></ul><ul><li>Ex: D1 obj=new D1(Add); </li></ul>
  10. 10. <ul><li>Invoking a Delegate : </li></ul><ul><li>Syntax: </li></ul><ul><li>DelegateobjectName(argslist); </li></ul><ul><li>Ex: obj(40,10); </li></ul>
  11. 11. <ul><li>http://www.akadia.com/services/dotnet_delegates_and_events.html </li></ul><ul><li>http://www.c-sharpcorner.com/UploadFile/ankithakur/Delegates06042007014105AM/Delegates.aspx </li></ul>
  12. 12. <ul><li>Thank You ! </li></ul>

×