No you can't overload generics methods like this.
Also you don't need to do this with generics.
You can create 2 methods like
public void MyMethod(int param1, int param2)
{
Console.WriteLine("int");
Console.WriteLine(param1.ToString());
Console.WriteLine(param2.ToString());
}
public void MyMethod(string param1, string param2)
{
Console.WriteLine(param1.ToString());
Console.WriteLine(param2.ToString());
}
and then you call them like this.
ListEx<stringlist = new ListEx<string>();
list.MyMethod(4, 5);
list.MyMethod("a", "b");
"Jure Bogataj" <ju**********@mikrocop.com>, iletisinde şunu yazdı,
news:e8**************@TK2MSFTNGP06.phx.gbl...
Hi all!
I was wondering if it is possible to create methods within generic
classes, based on what type class operates on:
e.g.
public class ListEx<T: List<T>
{
public void MyMethod<int>(int param1, int param2)
{
}
public void MyMethod<string>(string param1, string param2)
{
}
}
So, MyMethod<intwould only be available if instance of class is
declared:
ListEx<int>
and MyMethod<stringwould only be available if class declared like:
ListEx<string>
Is this at all possible with generics?
Thanks in advance!
Best regards, Jure