मैं कैसे समझ सामान्य की कमी से काम के साथ एक समस्या है। मुझे लगता है कि मुझे यहां कुछ महत्वपूर्ण याद आ रहा है। मैंने टिप्पणियों में अपने प्रश्न संलग्न किए हैं और कुछ स्पष्टीकरण प्रदान करने के लिए आभारी होंगे।टी पर जेनेरिक बाधा संदर्भ प्रकार और मूल्य प्रकार के साथ-साथ?
//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?
हां? तथा ? आपने इसे टी के लिए निर्दिष्ट किया है, जो ऑब्जेक्ट कन्स्ट्रक्टर से मेल खाता है। ठीक है। –
हाँ आप सही हैं, मैंने इसे गलत पढ़ा है। @ मार्क बार्स आपने कहा था कि सभी structs 'ऑब्जेक्ट' से प्राप्त होते हैं। यदि ऐसा है तो मैं 'वर्ग सीएस जहां टी था: वर्ग {}' कोड 'सीएस obj = नए सीएस () की तरह,' जबकि कार्य नहीं करेगा 'DateTime' आपत्ति उठाने castable है। –
nan
@Andrzej Nosal: हाँ, क्योंकि बाधा 't: class' मतलब यह नहीं है * टी आपत्ति उठाने castable है *। इसका मतलब है * टी एक संदर्भ प्रकार होना चाहिए *। डेटटाइम एक संदर्भ प्रकार नहीं है। –