您如何找到调用者函数? [英] How do you find the caller function?
本文介绍了您如何找到调用者函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Closed as exact duplicate of "How can I find the method that called the current method?"
是使用c#可以吗?
void main()
{
Hello();
}
void Hello()
{
// how do you find out the caller is function 'main'?
}
推荐答案
Console.WriteLine(new StackFrame(1).GetMethod().Name);
但是,这并不可靠,尤其是优化(例如JIT内联)可能会让人感觉到堆叠框架。
However, this is not robust, especially as optimisations (such as JIT inlining) can monkey with the perceived stack frames.
这篇关于您如何找到调用者函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文