how to add two integer and float variables?
class genericclass<T>
{
private T a;
private T b;
public void sum(T val1, T val2)
{
Console.WriteLine(" sum is "+ (val1 + val2));
}
}
class Program
{
static void Main(string[] args)
{
genericclass<int> gcint1= new genericclass<int>;
gcint1.sum(2, 3);
genericclass<float> gcfloat1=new genericclass<float>;
gcfloat1.sum(2.0, 3.0);
}
}
Generics
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.
Bechir BejaouiRank #144 · 15.9K pointsPosted Sep 16, 2010, 4:19 PM EDT
Oh I suffred a lot from that in the past like you but fortunetly there is a solution to that issue in the .net 4.0 the solution is the dynamic keyword
I invite you to take a look on my article the section where I discuss the generic issue
http://www.c-sharpcorner.com/UploadFile/yougerthen/3140/Default.aspx