什么比somestring =""更好 [英] What's better then somestring=""
问题描述
我明白了
如果somestring.length = 0那么
比那更快
如果somestring =""然后
相当于
如果(somestring是Nothing)AndAlso(somestring ="")那么
这是正确的吗?
还有更好的东西:
somestring =""
谢谢
有string.empty
http://msdn.microsoft.com/library/de...emptytopic.asp
Ken
-----------------
" ** **开发" < RE ************* @ a-znet.com>在消息中写道
新闻:OE ************** @ tk2msftngp13.phx.gbl ...我理解
如果somestring.length = 0那么
会更快
如果somestring =""然后
等同于
如果(somestring是Nothing)AndAlso(somestring ="")那么
这是正确的吗? ?
还有更好的东西:
somestring =""
谢谢
somestring = string.empty应该比使用"更快,因为只要你使用双引号,就会在内存中创建新的字符串对象,但是当你使用时
string.empty,你正在与一个已知常数进行比较。
" ** **开发" < RE ************* @ a-znet.com>在消息中写道
新闻:OE ************** @ tk2msftngp13.phx.gbl ...我理解
如果somestring.length = 0那么
会更快
如果somestring =""然后
等同于
如果(somestring是Nothing)AndAlso(somestring ="")那么
这是正确的吗? ?
还有更好的东西:
somestring =""
谢谢
somestring = string.empty应该比使用"更快,因为只要你使用双引号,就会在内存中创建新的字符串对象,但是当你使用
string.empty时,你正在与一个已知常量进行比较。
不,你会得到两个相同的空字符串对象案例。试试这个
Dim s1 As String =""
Dim s2 As String =""
Console。 WriteLine(s1是s2)
Console.WriteLine(s1是String.Empty)
Mattias
-
Mattias Sj?gren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
请回复到新闻组。
I understand that
If somestring.length = 0 Then
is faster then
If somestring = "" Then
and is equivalent to
If (somestring is Nothing) AndAlso (somestring = "") Then
Is that correct???
Also is there something better then:
somestring = ""
Thanks
Hi,
There is string.empty
http://msdn.microsoft.com/library/de...emptytopic.asp
Ken
-----------------
" **Developer**" <RE*************@a-znet.com> wrote in message
news:OE**************@tk2msftngp13.phx.gbl...I understand that
If somestring.length = 0 Then
is faster then
If somestring = "" Then
and is equivalent to
If (somestring is Nothing) AndAlso (somestring = "") Then
Is that correct???
Also is there something better then:
somestring = ""
Thanks
somestring = string.empty should be faster than using "", since anytime you
use double quotes, new string object is created in memory, but when you use
string.empty, you are comparing against a known constant.
" **Developer**" <RE*************@a-znet.com> wrote in message
news:OE**************@tk2msftngp13.phx.gbl...I understand that
If somestring.length = 0 Then
is faster then
If somestring = "" Then
and is equivalent to
If (somestring is Nothing) AndAlso (somestring = "") Then
Is that correct???
Also is there something better then:
somestring = ""
Thanks
somestring = string.empty should be faster than using "", since anytime you
use double quotes, new string object is created in memory, but when you use
string.empty, you are comparing against a known constant.
No, you''ll get the same empty string object in both cases. Try this
Dim s1 As String = ""
Dim s2 As String = ""
Console.WriteLine(s1 Is s2)
Console.WriteLine(s1 Is String.Empty)
Mattias
--
Mattias Sj?gren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
这篇关于什么比somestring =""更好的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!