C#从静态函数内打印类名 [英] c# print the class name from within a static function
本文介绍了C#从静态函数内打印类名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否有可能从一个静态函数内打印类名?
如...
公共类Foo
{
静态无效printName()
{
//打印类的名称,例如富
}
}
解决方案
Console.WriteLine(新的StackFrame()实现getMethod()DeclaringType);
Is it possible to print the class name from within a static function?
e.g ...
public class foo
{
static void printName()
{
// Print the class name e.g. foo
}
}
解决方案
Console.WriteLine(new StackFrame().GetMethod().DeclaringType);
这篇关于C#从静态函数内打印类名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文