string s;
Is there a difference between:
s = String.Empty;
and
s = "";
?
Well, of course there is, here's the IL code:
IL_0000: ldsfld string [mscorlib]System.String::Empty
IL_0005: stloc.0
IL_0006: ldstr ""
IL_000b: stloc.0
Wouldn't 's = ""' be oh-so-slightly faster?
Are there any side-effects to the two techniques?
Or are they in fact identical? (I don't know the difference between ldsfld
and ldstr.)
Thanks.
-glenn-
news:#XxiDDs6BHA.1924@tkmsftngp07
in this scenario, String.Empty was a bit faster.
--
Yizhaq Shmaayahoo
"-glenn-" <som...@example.com> wrote in message news:uQ8EdyY7BHA.1908@tkmsftngp05...
-glenn-
"Isaac Sh" <isaacsh(at)walla.co.il> wrote in message
news:OFFxIOZ7BHA.1912@tkmsftngp03...
| |||||
str=="" | str.Equals("") | str==string.Empty | str.Equals(string.Empty) | str.Length==0 | |
Empty string | 16 | 18 | 16 | 18 | 12 |
Normal string | 23 | 16 | 22 | 15 | 12 |
Long string | 23 | 16 | 22 | 15 | 12 |
since .NET has to create a string-instance every time you use "" in your
code, the static empty-Member of the string class will be faster.
"-glenn-" <som...@example.com> schrieb im Newsbeitrag
news:uQ8EdyY7BHA.1908@tkmsftngp05...
Thanks, Daniel.
-glenn-
"Daniel Weber" <dc...@gmx.de> wrote in message
news:aae73m$3ie$01$1...@news.t-online.com...
"Daniel Weber" <dc...@gmx.de> wrote in message
news:aae73m$3ie$01$1...@news.t-online.com...