I want to create a generic class in which a class type can handle strings.
I want to use this class for any class that has a static Parse (string) function, like System.Int32, System.Double, but also for classes like System.Guid. All have a static Parse function.
Thus, my class needs a where clause, which restricts my generic type to types using the Parse function
I would like to use it as follows:
class MyGenericClass<T> : where T : ??? what to do ???
{
private List<T> addedItems = new List<T>()
public void Add(T item)
{
this.AddedItems.Add(item);
}
public void Add(string itemAsTxt)
{
T item = T.Parse(itemAsTxt);
this.Add(item);
}
}
What to write in the where clause?
source
share