आपके उदाहरण में List<T>
एक सामान्य प्रकार की परिभाषा है। T
को सामान्य प्रकार पैरामीटर कहा जाता है। जब टाइप पैरामीटर List<string>
या List<int>
या List<double>
में निर्दिष्ट किया गया है तो आपके पास एक सामान्य प्रकार है। आप देख सकते हैं कि इस तरह की कुछ कोड चलाकर ...
System.Collections.Generic.List`1[System.String] //The Generic Type.
True //This is a generic type.
False //But it isn't a generic type definition because the type parameter is specified
System.Collections.Generic.List`1[T] //The Generic Type definition.
True //This is a generic type too.
True //And it's also a generic type definition.
public static void Main()
{
var l = new List<string>();
PrintTypeInformation(l.GetType());
PrintTypeInformation(l.GetType().GetGenericTypeDefinition());
}
public static void PrintTypeInformation(Type t)
{
Console.WriteLine(t);
Console.WriteLine(t.IsGenericType);
Console.WriteLine(t.IsGenericTypeDefinition);
}
कौन सा प्रिंट होगा सामान्य प्रकार परिभाषा सीधे typeof(List<>)
या typeof(Dictionary<,>)
है पाने के लिए एक और तरीका है।
स्रोत
2010-04-02 02:47:31
अहह्ह और यह सब अब समझ में आता है – Micah
ग्रेट स्पष्टीकरण। – wonde