传递“和”之间是否存在差异?并将Nothing传递给Windows API? [英] Is there a difference between passing "" and passing Nothing to a Windows API ?

查看:62
本文介绍了传递“和”之间是否存在差异?并将Nothing传递给Windows API?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我声明一个引用变量时,我将它初始化为Nothing。


现在我想知道对于String变量是否最好 - 是"更好吗?


没有什么我认为没有留下任何记忆也没有GC''ed


但是用"它是 - 正确吗?


系统似乎处理null与"相同。


例如:


s = A& 更多文字 ''如果A = Nothing或A =""


这样运行相同的代码吗?


如何通过到Windows API?


传递"之间是否存在差异?什么都没有?

谢谢



When I declare a reference variable I initialize it to Nothing.

Now I''m wondering if that best for String variables - is "" better?

With Nothing I assume no memory is set aside nor GC''ed

But with "" it is - correct?

The system seems to handle a null the same as "".

For example:

s=A & "more text" ''Works the same if A=Nothing or A=""

Does this run the same code?

What about passing to a Windows API?

Is there a difference between passing "" and passing Nothing?
Thank you




推荐答案

>传递和之间是否存在差异?什么都没有?


他们是不同的。最简单的例子就是

i = Len(s)

i = s.Length

s.Length如果s什么也不会失败。一些vb字符串处理将工作正常

(和相同)与"没别的了。一般来说,vb遗留字符串处理

应对两者,但面向对象的功能对待它们的方式不同。

FYI,我的习惯是避免使用字符串。
> Is there a difference between passing "" and passing Nothing?

They are different. The simplest example of the difference is with
i = Len(s)
i = s.Length
s.Length will fail if s is nothing. Some vb string handling will work fine
(and identically) with "" and nothing. Generally, vb legacy string handling
copes with both, but object oriented functionality treats them differently.
FYI, my habit is to avoid Nothing with strings.


使用

空字符串值初始化字符串值被视为良好的编码习惯


dim x as string = "



dim x as string = string.empty

如果你不这样做,你应该总是使用这个


如果不是x什么都没有那么

''必须在处理之前检查没有

结束如果


问候


Michel Posseth [MCP]


"学术" <交流****** @ a-znet.com> schreef in bericht

新闻:eT *************** @ TK2MSFTNGP15.phx.gbl ...
it is considered good coding practice to initialize string values with a
empty string value

dim x as string =""
or
dim x as string=string.empty
if you do not do this you should always use this

if not x is nothing then
'' must check for nothing before processing
end if

regards

Michel Posseth [MCP]

" academic" <ac******@a-znet.com> schreef in bericht
news:eT***************@TK2MSFTNGP15.phx.gbl...
当我宣布一个引用变量我将它初始化为Nothing。

现在我想知道对于String变量来说是否最好 - 是"更好吗?

没有什么我认为没有留下任何记忆也没有GC''

但是用"它是 - 正确吗?

系统似乎处理null与"相同。

例如:

s = A &安培; 更多文字 ''如果A = Nothing或A ="

这样运行相同的代码吗?

如何传递到Windows API?
传递"之间是否存在差异?什么都没有?

谢谢


When I declare a reference variable I initialize it to Nothing.

Now I''m wondering if that best for String variables - is "" better?

With Nothing I assume no memory is set aside nor GC''ed

But with "" it is - correct?

The system seems to handle a null the same as "".

For example:

s=A & "more text" ''Works the same if A=Nothing or A=""

Does this run the same code?

What about passing to a Windows API?

Is there a difference between passing "" and passing Nothing?
Thank you




>但是用和 ;"它是 - 对吗?


是的。但是,如果合适的话,这不应该阻止你使用它。

>But with "" it is - correct?

Yes. But that shouldn''t stop you from using it if appropriate.

系统似乎处理null与"相同。


取决于您对系统的含义。 VB语言和

库经常试图隐藏差异,但在.NET

框架中,通常存在显着差异。

如何传递到Windows API?

传递"之间是否存在差异?什么都没有?
The system seems to handle a null the same as "".
Depends on what you mean by "the system". The VB language and
libraries often tries to hide the difference but in the the .NET
framework there''s usually a significant difference.

What about passing to a Windows API?

Is there a difference between passing "" and passing Nothing?




是的。

Mattias


-

Mattias Sj?gren [C#MVP] mattias @ mvps.org
http ://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com

请回复到新闻组。



Yes.
Mattias

--
Mattias Sj?gren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.


这篇关于传递“和”之间是否存在差异?并将Nothing传递给Windows API?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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