将字符串初始化为Nothing或“"”? [英] Intialize String to Nothing or ""?

查看:67
本文介绍了将字符串初始化为Nothing或“"”?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好 -


这可能是一个愚蠢的问题,但我想知道是否有a

初始化字符串的首选方法。所以要么...

Dim lDummy As String = Nothing

....或者......

Dim lDummy As String =" ;"


谢谢,

Joe

Hello -

This might be a silly question but I was wondering if there is "a"
preferred way of initializing a String ... so either ...
Dim lDummy As String = Nothing
.... or ...
Dim lDummy As String = ""

Thanks,
Joe

推荐答案






String.Empty?

dim abc as string = string.Empty


我自己去了字符串。我自己。这是一个美元。


" Joe Duchtel" < du ***** @ gmail.com写信息

新闻:98 ************************* ********* @ d23g2000 yqc.googlegroups.com ...

or

String.Empty ?
dim abc as string = string.Empty

I go with the string.Empty myself.


"Joe Duchtel" <du*****@gmail.comwrote in message
news:98**********************************@d23g2000 yqc.googlegroups.com...

你好 -


这个可能是一个愚蠢的问题,但我想知道是否有a

初始化字符串的首选方式......所以......

Dim lDummy As String =没有什么

......或者......

Dim lDummy As String =""


谢谢,

Joe
Hello -

This might be a silly question but I was wondering if there is "a"
preferred way of initializing a String ... so either ...
Dim lDummy As String = Nothing
... or ...
Dim lDummy As String = ""

Thanks,
Joe



11月20日,8:57 * pm,Joe Duchtel< duch ... @ gmail .comwrote:
On Nov 20, 8:57*pm, Joe Duchtel <duch...@gmail.comwrote:

你好 -


这可能是一个愚蠢的问题,但我想知道是否有a

初始化字符串的首选方式...所以要么...

Dim lDummy As String = Nothing

...或.. 。

Dim lDummy As String =""


谢谢,

Joe
Hello -

This might be a silly question but I was wondering if there is "a"
preferred way of initializing a String ... so either ...
Dim lDummy As String = Nothing
... or ...
Dim lDummy As String = ""

Thanks,
Joe



他们不一样。空字符串(String.Empty或")用于

为变量赋值空值。但是将其设置为Nothing

表示没有赋值给变量(null引用),并且相同的

表示Dim IDummy As String。 />

所以,你需要在进一步的

处理中选择你对字符串的处理方式。如果你在项目中也使用那个

实例,我宁愿给它分配一个值。


另见:
http:// www.experts-exchange.com/Prog..._23787895.html

希望这会有所帮助,

They are not the same. An empty string (String.Empty or "") is used to
assign an empty value to the variable. But setting it to "Nothing"
means no value is assigned to the variable(null reference), and same
as "Dim IDummy As String".

So, you need to choice what you''ll do with the string in further
processing. I''d prefer to assign a value to it if you''ll use that
instance in your project as well.

Also see this:
http://www.experts-exchange.com/Prog..._23787895.html
Hope this helps,


11月20日, 2:13 * pm,kimiraikkonen< kimiraikkone ... @ gmail.comwrote:
On Nov 20, 2:13*pm, kimiraikkonen <kimiraikkone...@gmail.comwrote:

11月20日,8:57 * pm,Joe Duchtel< duch。 .. @ gmail.comwrote:
On Nov 20, 8:57*pm, Joe Duchtel <duch...@gmail.comwrote:

你好 -
Hello -


这可能是个傻瓜问题,但我想知道是否有a

初始化字符串的首选方式......所以......

Dim lDummy As String = Nothing

...或......

Dim lDummy As String =""
This might be a silly question but I was wondering if there is "a"
preferred way of initializing a String ... so either ...
Dim lDummy As String = Nothing
... or ...
Dim lDummy As String = ""


谢谢,

Joe
Thanks,
Joe



他们不是相同。空字符串(String.Empty或")用于

为变量赋值空值。但是将其设置为Nothing

表示没有赋值给变量(null引用),并且相同的

表示Dim IDummy As String。 />

所以,你需要在进一步的

处理中选择你对字符串的处理方式。如果你在项目中也使用那个

实例,我宁愿给它分配一个值。


另见:< a rel =nofollowhref =http://www.experts-exchange.com/Programming/Languages/.NET/Visual_Bastarget =_ blank> http://www.experts-exchange.com/Prog。 ..NET / Visual_Bas ...


希望这会有所帮助,


They are not the same. An empty string (String.Empty or "") is used to
assign an empty value to the variable. But setting it to "Nothing"
means no value is assigned to the variable(null reference), and same
as "Dim IDummy As String".

So, you need to choice what you''ll do with the string in further
processing. I''d prefer to assign a value to it if you''ll use that
instance in your project as well.

Also see this:http://www.experts-exchange.com/Prog...NET/Visual_Bas...

Hope this helps,



您好 -


我在expert-exchange.com上看不到解决方案,因为我没有订阅




我确实没有什么意思,但如果我将它初始化为Nothing后使用Console.WriteLine

(lDummy),它将输出一个空的
字符串。


谢谢,

Joe

Hello -

I cannot see the solutions in experts-exchange.com as I don''t have a
subscription.

I do realize that Nothing means nothing but if I use Console.WriteLine
(lDummy) after I initialize it to Nothing, it will output an empty
string.

Thanks,
Joe


这篇关于将字符串初始化为Nothing或“&quot;”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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