C# में Type.GetNestedType() विधि का उपयोग वर्तमान प्रकार के भीतर एक विशिष्ट प्रकार के नेस्टेड को प्राप्त करने के लिए किया जाता है।
सिंटैक्स
निम्नलिखित वाक्य रचना है -
public Type GetNestedType (string name); public abstract Type GetNestedType (string name, System.Reflection.BindingFlags bindingAttr);
उदाहरण
आइए अब Type.GetNestedType() विधि को लागू करने के लिए एक उदाहरण देखें -
using System;
public class Demo {
public static void Main(){
Type type1 = typeof(Subject);
try {
Type type2 = type1.GetNestedType("AdvSubject");
Console.Write("NestedType = "+ type2);
}
catch (ArgumentNullException e){
Console.Write("{0}", e.GetType(), e.Message);
}
}
}
public class Subject{
public class BasicSubject {
//
}
public class AdvSubject {
//
}
} आउटपुट
यह निम्नलिखित आउटपुट देगा -
NestedType = Subject+AdvSubject
उदाहरण
आइए अब Type.GetNestedType() विधि को लागू करने के लिए एक और उदाहरण देखें -
using System;
public class Demo {
public static void Main(){
Type type1 = typeof(Subject);
try {
Type type2 = type1.GetNestedType(null);
Console.Write("NestedType = "+ type2);
}
catch (ArgumentNullException e){
Console.Write("{0}", e.GetType(), e.Message);
}
}
}
public class Subject{
public class BasicSubject {
//
}
public class AdvSubject {
//
}
} आउटपुट
यह निम्नलिखित आउटपुट देगा -
System.ArgumentNullException