Общее ограничение для T быть одновременно ссылочным типом и типом значения?

У меня проблема с пониманием того, как работают общие ограничения. Думаю, я упускаю здесь что-то важное. Я заключил свои вопросы в комментарии и был бы признателен за некоторые пояснения.

//1st example:

class C <T, U>
    where T : class
    where U : struct, T
{
}
//Above code compiles well, 
//On first sight it looks like U might be reference type and value type
//at the same time. The only reason I can think of, is that T may be an 
//interface which struct can implement, Am I correct?

//2nd example

class CC<T, U>
    where T : class, new ()
    where U : struct, T
{
}

//I added also a reguirement for parameterless constructor
//and, much to my surprise, it still compiles what is
//a bit inexplicable for me.
//What 'U' would meet the requirement to be 
//value type, reference type and have a contructor at the same time?
14
задан Cœur 15 October 2017 в 11:58
поделиться