Visual Basic .NET » Internet / Hardware Communication
Generics Programming in C# -- sillyemperor --


I wanna create a class named Vector2D,but i dislike code like this
"double x,y;",so I want to use GP ,but fallen into disorder,look codes below:

class Vector2D<T>
{
T x;
T y;
...
void add(Vector2D<T> a)
{
x += a.x; //error!
y += b.y; //error!
}
...
}

Then i search in web, found two resolutions:
http://www.codeproject.com/csharp/genericnumerics.asp 
i choose the one below ,and use interface instead of delegate.

I wonder why MS do not make it more easy to be used,GP is a very useful feature after all.

[Submit Comment]Home