Type.GetNestedType(string name) মেথড ব্যবহার করে নির্দিষ্ট নামে একটি নেস্টেড টাইপ পাওয়া যায়। নাম না পেলে null রিটার্ন করে; null পাস করলে ArgumentNullException থ্রো করে।
উদাহরণ ১: বিদ্যমান নেস্টেড টাইপ পাওয়া
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 পাস করলে এক্সেপশন
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
সারসংক্ষেপ
GetNestedType(name)— নির্দিষ্ট নামের নেস্টেড টাইপ রিটার্ন করে (পাবলিক)।GetNestedType(name, BindingFlags)— নন-পাবলিকও খুঁজে পাওয়া যায়।- নাম কেস-সেনসিটিভ।
nullআর্গুমেন্ট দিলেArgumentNullException।