C# Generic Constraints Part 2

preview_player
Показать описание
Jamie King enumerating the various possible generic constraints.
Рекомендации по теме
Комментарии
Автор

This tutorial so much better than the recent ones

---webx
Автор

Thanks Jamie. Your videos rock. You really help make it 'click.'

CodeDreamer
Автор

From your previous video, how can I declare constraint type classTwo without inheriting from ClassOne? Can I do this?
public ClassTwo(int i, char c)
{

}

static T ProduceMethod<T>() where T:ClassTwo
{
T returnvalue = new T(); // I get an error bacause I dont have new() cinstraint on T
// int i = 4
// cahr c = 'A';
// T returnvalue = new T(i, c); I still get the error here
return returnvalue;
}

ajaykomireddy
Автор

It's Ctrl-M-L to collapse everything, and Ctrl-M-M to collapse a single fold :)

vexedev