Hello All
I found some *issue* with the generics in C#. It looks like an issue to
me :
In C++ the following code compiles fine
class Person
{
public:
char last[10];
};
template <typename T>
class MyClass
{
T x;
public:
void call()
{
char copy[10];
strcpy(copy,x.last);
....
}
};
However a similar code fails to compile in C#
class Person
{
public string lastName;
}
class MyClass<T>
{
private T x;
public void Call()
{
string s = x.lastName;//COMPILER ERROR HERE
}
}
from what I understand, the compiler is not expanding the code ,rather
the code is *expanded* at runtime.
Does it mean you can never access any "function" of T even if you want
to do something like what I did above.
If this is true then it looks like a serious drawback of generics to
me.
because the compiler does a check for T t
}
}