C# में Type.GetNestedType() मेथड का उपयोग वर्तमान Type के भीतर एक विशिष्ट नेस्टेड प्रकार को प्राप्त करने के लिए किया जाता है।
सिंटैक्स
निम्नलिखित सिंटैक्स हैं:
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
एक और उदाहरण (null पास करने पर)
आइए null पास करने का एक उदाहरण देखते हैं:
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