public class 妓女
{
public static string 上()
{
System.Diagnostics.StackFrame frame = new System.Diagnostics.StackFrame(0);
return frame.GetMethod().ReflectedType.Name;
}
}
public class 嫖客A : 妓女
{ }
public class 嫖客B : 妓女
{}
static void Main()
{
Console.WriteLine(嫖客A.上());
Console.Read();
}public class 妓女
{
public static string 上()
{
return System.Reflection.MethodBase.GetCurrentMethod().ReflectedType.Name;
}
}
public class 嫖客A : 妓女
{ }
public class 嫖客B : 妓女
{}
static void Main()
{
Console.WriteLine(嫖客A.上());
Console.Read();
}
=====================================================
上面对2种方法都不行,返回的都不是"妓女",讨论下怎么才能让"妓女"知道是谁"上"了它!!!
{
public static string 上()
{
System.Diagnostics.StackFrame frame = new System.Diagnostics.StackFrame(0);
return frame.GetMethod().ReflectedType.Name;
}
}
public class 嫖客A : 妓女
{ }
public class 嫖客B : 妓女
{}
static void Main()
{
Console.WriteLine(嫖客A.上());
Console.Read();
}public class 妓女
{
public static string 上()
{
return System.Reflection.MethodBase.GetCurrentMethod().ReflectedType.Name;
}
}
public class 嫖客A : 妓女
{ }
public class 嫖客B : 妓女
{}
static void Main()
{
Console.WriteLine(嫖客A.上());
Console.Read();
}
=====================================================
上面对2种方法都不行,返回的都不是"妓女",讨论下怎么才能让"妓女"知道是谁"上"了它!!!
解决方案 »
- ZedGraph 如何清空数据
- 【奇怪】在IE地址里可以访问的地址,到了WebRequest.GetResponse()后报了500错误
- 如何把两个字符串和一个从表中读出的值合并成一个sql语句?请高手指点一下。万分感谢。
- FastReport for .NET 1.3 问题
- 一个困扰很久的简单问题,大家帮忙解决
- 请教相关DataGridView的问题
- C#工具条的button怎样给他添加快捷键?
- 100分求助,怎样获得当前登录页面的用户的信息(域帐户)
- -----------------高手请进,是不是VS2002的版本的DateGrid里的数据不能自动换行?
- C# Dllimport的问题
- 使用Myxls操作excel 如何插入图片?
- DataGridView格式化日期输入问题
另外就是:编译器会把继承类的静态调用编译成直接调用基类的。也就是 嫖客A.上 在IL中是 妓女A.上,搞不清楚的。
class Program
{
public class Hooker
{
public virtual string Visit()
{
return "Hooker";
}
}
public class WhoremasterA : Hooker
{
public override string Visit()
{
return "WhoremasterA";
}
}
public class WhoremasterB : Hooker
{
public override string Visit()
{
return "WhoremasterB";
}
} static void Main(string[] args)
{
Hooker hookerA = new WhoremasterA();
Hooker hookerB = new WhoremasterB();
Console.WriteLine(hookerA.Visit());
Console.WriteLine(hookerB.Visit());
Console.Read();
}
}
{
public string 上()
{
return this.GetType().Name;
}
}
public class 嫖客A : 妓女
{ }
public class 嫖客B : 妓女
{ } static void Main(string[] args)
{
嫖客A a = new 嫖客A();
Console.WriteLine(a.上());
嫖客B b = new 嫖客B();
Console.WriteLine(b.上());
Console.Read();
}
/*
输出:
嫖客A
嫖客B*/