publicinterface IData<T>: IDisposable
{
voidAdd(T data);
T Get();
}
publicclassUser<T>: IData<T>
{
T user;
publicvoidAdd(T data)
{
this.user = data;
}
publicvoidDispose()
{
thrownewNotImplementedException();
}
public T Get()
{
returnthis.user;
}
}
Adding User
1
2
3
4
5
6
7
8
9
10
11
12
publicclassGenericsClasswithConstraint
{
staticvoidMain(string[] args)
{
var user = new User<string>();
user.Add("Ram");
Console.WriteLine($"User \"{user.Get()}\" has been added");
Console.ReadLine();
}
}
No comments:
Post a Comment