C# StackTrace 不包括对 new 运算符的调用
我来自 C++,我不明白为什么在 C# 中,当我编写:
class A {
public A(){ /*here I get the StackTrace */}
//......other code
void f(){ A a = new A();
}
当我检查构造函数内的 StackTrace 对象时,我无法在“f()”函数调用和“ A()”构造函数。
为什么省略了 new() 运算符?或者我做错了什么?
I come from C++ and I don't understand why in C# when I write :
class A {
public A(){ /*here I get the StackTrace */}
//......other code
void f(){ A a = new A();
}
When I inspect the StackTrace object inside the constructor I can't find the call to the new() operator between "f()" function call and the "A()" constructor.
Why is the the new() operator omitted? or am I doing something wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
没有单独的
new
函数调用。只是构造函数调用。There is no separate
new
function call. Just the constructor call.我的 .Net 反汇编技能可能很弱,但这是我分配两个不同对象的结果:
我解释这一点的方式是“new X()”计算为两个单独的调用。第一个可能是“内存分配”,而第二个调用是对象的构造函数。我这样说是因为两个语句调用的第一个方法是相同的(即使它们是不同的类型),并且每种情况下的第二个调用都是不同的。
如果有人知道如何验证这些特定地址的评估结果,我很想知道。
My .Net Disassembly skill smay be weak, but here is what I get allocating two different objects:
The way I am interpreting this is that "new X()" evaluates to two seperate calls. The first might be the "memory allocation" while the second call is the constructor of the object. I say this because the first method called by both statements is the same (even though they are different types), and the second call in each case is different.
If anyone knows how to verify what these specific addresses evaluate to, I would love to know.