如果有疑问 - 写代码 - 但...... [英] When in doubt - write code - but ...

查看:82
本文介绍了如果有疑问 - 写代码 - 但......的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我总是被告知 - 当有疑问时 - 把它写出来然后运行它看看

你自己发生了什么。


但最近有人告诉我,如果我有一个值类型并且我传递它

byref,它将始终打包/取消装箱。我如何找到真相?


- Sahil Malik
http://dotnetjunkies.com/weblog/sahilmalik

So I have always been told - when in doubt - write it out and run it and see
for yourself what happens.

But someone recently told me that if I have a value type and I pass it
byref, it will always box/unbox it. How do I find the truth?

- Sahil Malik
http://dotnetjunkies.com/weblog/sahilmalik

推荐答案



" Sahil Malik <共***************** @ nospam.com>在消息中写道

news:u9 ************** @ TK2MSFTNGP10.phx.gbl ...

"Sahil Malik" <co*****************@nospam.com> wrote in message
news:u9**************@TK2MSFTNGP10.phx.gbl...
所以我一直都是告诉 - 当有疑问时 - 把它写出来并运行它
看看
自己发生了什么。

但最近有人告诉我,如果我有一个值类型并且我通过它是
byref,它总是打包/取消装箱。我如何找到真相?
So I have always been told - when in doubt - write it out and run it and
see
for yourself what happens.

But someone recently told me that if I have a value type and I pass it
byref, it will always box/unbox it. How do I find the truth?




不,将它作为一个对象传递给一个盒子,通过ref传递它或者传递

结果在传递的堆栈地址中(ldloca指令)



No, passing it as an object results in a box, passing it via ref or out
results in the stack address being passed(ldloca instruction)


Sahil ....使用反汇编程序查看由

生成的IL字节代码这两种方法。
http://www.geocities.com/ jeff_louie / il__net.htm

问候,

杰夫

如何找到真相?

***通过开发人员指南 http://www.developersdex.com 发送***

不要只是参加USENET ......获得奖励!
Sahil.... Use the disassembler to look at the IL byte code generated by
the two approaches.
http://www.geocities.com/jeff_louie/il__net.htm
Regards,
Jeff
How do I find the truth?

*** Sent via Developersdex http://www.developersdex.com ***
Don''t just participate in USENET...get rewarded for it!


嗯..我是这么认为的! !!


- Sahil Malik
http ://dotnetjunkies.com/weblog/sahi lmalik

Daniel O''Connell [C#MVP]" < onyxkirx @ - NOSPAM--comcast.net>写在

消息新闻:eQ ************** @ TK2MSFTNGP09.phx.gbl ...
Hmm .. I thought so !!!!

- Sahil Malik
http://dotnetjunkies.com/weblog/sahilmalik
"Daniel O''Connell [C# MVP]" <onyxkirx@--NOSPAM--comcast.net> wrote in
message news:eQ**************@TK2MSFTNGP09.phx.gbl...

" ; Sahil Malik <共***************** @ nospam.com>在消息中写道
新闻:u9 ************** @ TK2MSFTNGP10.phx.gbl ...

"Sahil Malik" <co*****************@nospam.com> wrote in message
news:u9**************@TK2MSFTNGP10.phx.gbl...
所以我一直被告知 - 在怀疑 - 把它写出来然后运行吧
看看
自己发生了什么。

但有人最近告诉我,如果我有一个值类型并且我通过它
byref,它将始终打包/取消装箱。我如何找到真相?
So I have always been told - when in doubt - write it out and run it and
see
for yourself what happens.

But someone recently told me that if I have a value type and I pass it
byref, it will always box/unbox it. How do I find the truth?



不,将其作为对象传递会产生一个框,通过ref或out传递它会导致堆栈地址被传递(ldloca)指示)



No, passing it as an object results in a box, passing it via ref or out
results in the stack address being passed(ldloca instruction)



这篇关于如果有疑问 - 写代码 - 但......的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆