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

Generics n delegates

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