Questions tagged [cil-metadata]
2 questions
5
votes
3 answers
Why cant you require operator overloading in generics
In C++, you can write code like this:
template
T Add(T lhs, T rhs)
{
return lhs + rhs;
}
But, you can't do something like this in C#:
public static T Add(T x, T y) where T : operator+
{
return x + y;
}
Is there any reason why?…

Cole Tobin
- 9,206
- 15
- 49
- 74
4
votes
3 answers
How does the C# compiler work with generics?
In C++, the template declarations need to be in a header file (unless you explicitly declare the template type), and I see understand why.
What I don't get is how the C# compiler can handle generics if it doesn't have the .cs file to examine. I…
anon