Adding Two Generic Variables

Nandkishorrech
Posted by Nandkishorrech under C# category on | Points: 40 | Views : 405
Here for adding , i am using generic variables. using these generic variables we can add any type of data.
ex: int,string,decimal,double etc..

Add<string>("dotnet ", "funda");
Add<int>(5, 1);


public class GenericClass
{
static void Main(string[] args)
{
Add<decimal>(5.5m, 10);
}

static void Add<T>(T a, T b)
{
Console.WriteLine((dynamic)a + (dynamic)b);
Console.ReadKey();
}
}

Comments or Responses

Login to post response