Possible Duplicate:
Solution for overloaded operator constraint in .NET generics
Implementing arithmetic in generics?
I wrote Generics class,but i am having issue as described in title.
class Program
{
static void Main(string[] args)
{
int a = 1;
int b = 2;
int c = 3;
dynamic obj = new Gen<int>();
obj.TestLine1(ref a, ref b);
obj = new Gen<string>();
obj.TestLine2(ref a, ref b, ref c);
System.Console.WriteLine(a + " " + b);
Console.ReadLine();
}
}
public class Gen<T>
{
public void TestLine1(ref T a, ref T b)
{
T temp;
temp = a;
a = b;
b = temp;
}
public void TestLine2(ref T a, ref T b, ref T c)
{
T temp;
temp = a;
a = a + b;
b = a + c;
c = a + b;
}
}
Inside at method TestLine2(ref T a, ref T b, ref T c) I am getting below issue:
Operator '+' cannot be applied to operands of type 'T' and 'T'