Type t=typeof(class1); System.Reflection.TypeAttributes ta = t.Attributes; string s = ta.ToString(); if (s.Contains("Abstract") && s.Contains("Sealed")) { Console.WriteLine("static class"); }
获取类的全名 判断有没有static class 嗯 嗯
反射!不解释哈哈~~~~突然想到一个笨办法嘿嘿:try实例化某类,如果catch到异常就不是静态类否则为静态滴~~~~~~哈哈也算是一种思路 但是正式用还是用反射吧: Type t=typeof(class1); System.Reflection.TypeAttributes ta = t.Attributes; string s = ta.ToString(); if (s.Contains("Abstract") && s.Contains("Sealed")) { Console.WriteLine("static class"); }
public static void CanMakeInstance(Type t)
{
try
{
Activator.CreateInstance(t);
Console.WriteLine("非静态类");
}
catch
{
Console.WriteLine("静态类");
}
}
System.Reflection.TypeAttributes ta = t.Attributes;
string s = ta.ToString();
if (s.Contains("Abstract") && s.Contains("Sealed"))
{
Console.WriteLine("static class");
}
获取类的全名 判断有没有static class 嗯 嗯
但是正式用还是用反射吧:
Type t=typeof(class1);
System.Reflection.TypeAttributes ta = t.Attributes;
string s = ta.ToString();
if (s.Contains("Abstract") && s.Contains("Sealed"))
{
Console.WriteLine("static class");
}
public static void CanMakeInstance(Type t)
{
try
{
Activator.CreateInstance(t);
Console.WriteLine("非静态类");
}
catch
{
Console.WriteLine……