的sizeof?是否有.NET等价物 [英] sizeof? is there a .NET equivalent

查看:95
本文介绍了的sizeof?是否有.NET等价物的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近需要使用kernel32.dll中的ZeroMemory,我发现了b $ b。显然没有.NET相当于c / c ++ sizeof

运算符 - 一个确实存在于Marshall命名空间中,但是当

传递一个托管类型时它会失败。我在Reflection命名空间周围戳了一下,但发现

没有任何合适的账单。在
..NET中是否存在等于sizeof的运行时间?

Having recently had a need to use ZeroMemory from the kernel32.dll, I
"discovered" that there is apparently no .NET equivalent to the c/c++ sizeof
operator -- one does exist in the Marshall namespace, but it fails when
passed a managed type. I poked around the Reflection namespace, but found
nothing that fits the bill. Is there a runtime equivalent to sizeof in
..NET?

推荐答案



stand__sure写道:

stand__sure wrote:
最近需要使用kernel32.dll中的ZeroMemory,I
已发现显然没有.NET等同于c / c ++
sizeof运算符 - 一个确实存在于Marshall命名空间中,但在传递托管类型时它会失败
。我在Reflection命名空间周围戳了一下,但是
发现什么都不符合要求。在.NET中是否存在等于sizeof
的运行时?
Having recently had a need to use ZeroMemory from the kernel32.dll, I "discovered" that there is apparently no .NET equivalent to the c/c++ sizeof operator -- one does exist in the Marshall namespace, but it fails when passed a managed type. I poked around the Reflection namespace, but found nothing that fits the bill. Is there a runtime equivalent to sizeof in .NET?





-

Larry Lard

回复团体请



Hmm well if Marshal.SizeOf is no good for you, how about Len(Object)?

--
Larry Lard
Replies to group please


这取自我过去编码的内容:


私有声明Sub ZeroMemory Lib" kernel32.dll"别名RtlZeroMemory _

(ByVal Destination As String,ByVal length as Integer)


ZeroMemory(txtPassword.Text,txtPassword.Text.Length * 2)


-------------------


Marshall.SizeOf在这里:


System.Runtime.InteropServices.Marshal


我希望这有帮助


Crouchie1998

BA(HONS)MCP MCSE
This is taken from something I have coded in the past:

Private Declare Sub ZeroMemory Lib "kernel32.dll" Alias "RtlZeroMemory" _
(ByVal Destination As String, ByVal Length As Integer)

ZeroMemory(txtPassword.Text, txtPassword.Text.Length * 2)

-------------------

The Marshall.SizeOf is here:

System.Runtime.InteropServices.Marshal

I hope this helps

Crouchie1998
BA (HONS) MCP MCSE


感谢您的回复 - 我最终使用了这种方法 - 我反对

it是它返回除了字符串之外的所有字节的字节数,在

这种情况​​下它返回字符数(仅需要这种类型的

乘法步骤 - 这个是可以管理但似乎是
a浪费的一步 - 像LenB这样的东西会很有用,但它已被弃用了

弃用了)


Larry Lard < LA ******* @ hotmail.com>在消息中写道

news:11 ********************** @ l41g2000cwc.googlegr oups.com ...
Thanks for the reply -- I did end up using this approach -- my objection to
it is that it returns the number of bytes for everything but strings, in
which case it returns the number of characters (necessitating a
multiplication step for only this type -- this is manageable but seems like
a wasteful step -- something like LenB would be useful, but it has been
deprecated)

"Larry Lard" <la*******@hotmail.com> wrote in message
news:11**********************@l41g2000cwc.googlegr oups.com...

stand__sure写道:

stand__sure wrote:
最近需要使用kernel32.dll中的ZeroMemory,我
Having recently had a need to use ZeroMemory from the kernel32.dll, I


"发现"显然没有.NET等同于c / c ++
"discovered" that there is apparently no .NET equivalent to the c/c++


sizeof


sizeof

运算符 - 一个确实存在于Marshall命名空间中,但它失败了
operator -- one does exist in the Marshall namespace, but it fails


传递托管类型时。我在Reflection命名空间周围戳了一下,但
passed a managed type. I poked around the Reflection namespace, but


找到了

没有任何符合条件的法案。在
nothing that fits the bill. Is there a runtime equivalent to sizeof
.NET中是否存在等于sizeof


in


的运行时?

.NET?



如果Marshal.SizeOf对你没有好处,那很好,Len(对象)怎么样?

-
Larry Lard
回复团体



Hmm well if Marshal.SizeOf is no good for you, how about Len(Object)?

--
Larry Lard
Replies to group please



这篇关于的sizeof?是否有.NET等价物的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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