Home All Groups Group Topic Archive Search About

Shall I now always use String.Empty instead of ""

Author
23 Nov 2006 9:57 AM
anonieko
In the past I always used "" everywhere for empty string in my code
without a problem.

Now, do you think I should use String.Empty instead of "" (at all
times) ?

Let me know your thoughts.

Author
23 Nov 2006 11:10 AM
Leon Mayne
"anoni***@hotmail.com" wrote:
> In the past I always used "" everywhere for empty string in my code
> without a problem.
>
> Now, do you think I should use String.Empty instead of "" (at all
> times) ?

If you're checking for an empty string it's better to use:
String.IsNullOrEmpty(strStringName)
As of .NET 2.0
Author
23 Nov 2006 2:23 PM
Morten Wennevik
Hi,

There is very little difference between the two.

"" is easy to write, easy to read, and near impossible to misunderstand.=
   =

It will however create an object where String.Empty would not, but the "=
"  =

object is reused throughout the lifespawn of your application so the  =

difference can therefore be ignored.

Neither will detect a null string so if you can have null strings you ne=
ed  =

to either check for that as well or use String.IsNullErEmtpy as Leon  =

pointed out.

if(str =3D=3D null || str =3D=3D "") // or
if(String.IsNullOrEmpty(str))

If, on the other hand, you know you will never get null strings, testing=
  =

for String.Length =3D=3D 0 is the fastest way.



On Thu, 23 Nov 2006 10:57:06 +0100, <anoni***@hotmail.com> wrote:

> In the past I always used "" everywhere for empty string in my code
> without a problem.
>
> Now, do you think I should use String.Empty instead of "" (at all
> times) ?
>
> Let me know your thoughts.
>



-- =

Happy Coding!
Morten Wennevik [C# MVP]
Author
23 Nov 2006 7:34 PM
Jon Shemitz
Morten Wennevik wrote:

> "" is easy to write, easy to read, and near impossible to misunderstand.
> It will however create an object where String.Empty would not, but the ""
> object is reused throughout the lifespawn of your application so the
> difference can therefore be ignored.

I was surprised to read that "" will create an object where
String.Empty will not - surely String.Empty is just a static field
that points to an interned "" constant?

Sure enough, Reflector shows that String.Empty is implemented as

  class string
  {
    static readonly string Empty = "";
  }

.... yet the below code shows that while both "" and String.Empty are
interned, "" is not reference-equal to String.Empty. What gives? I
thought the intern table was maintained across assembly boundaries, so
it shouldn't matter that String.Empty comes from mscorlib.dll while ""
comes from the app assembly.

//

using System;

namespace StringEmptyTest
{
  class Program
  {
    static void Main(string[] args)
    {
      Console.WriteLine(Object.ReferenceEquals(String.Empty, ""));
      Console.WriteLine(String.IsInterned("") != null);
      Console.WriteLine(String.IsInterned(String.Empty) != null);
      Console.ReadLine();
    }
  }
}


--

..NET 2.0 for Delphi Programmers
www.midnightbeach.com/.net
What you need to know.
Author
29 Nov 2006 12:39 AM
Dave Sexton
Hi Jon,

Your example code has been bothering me - it should work, however it doesn't
and I can't figure out why :p

But if you think that's weird, check out the following documentation I found
on MSDN:

"String.Intern Method"
http://msdn2.microsoft.com/en-us/library/system.string.intern.aspx

<quote>
Version Considerations
Starting with the .NET Framework version 2.0, there is a behavioral change
in the Intern method. In the following C# code sequence, the variable str1
is assigned a reference to Empty, the variable str2 is assigned the
reference to Empty that is returned by the Intern method, then the
references contained in str1 and str2 are compared for equality.

string str1 = String.Empty;
string str2 = String.Intern(String.Empty);
if ((object) str1) == ((object) str2) .

In the .NET Framework version 1.1, str1 and str2 are not equal, but starting
in the .NET Framework version 2.0, str1 and str2 are equal.
</quote>

Not in my test :|

string str1 = String.Empty;
string str2 = String.Intern(String.Empty);

// false
Console.WriteLine((object) str1 == (object) str2);

// false
Console.WriteLine((object) string.Empty == (object) "");

// true
Console.WriteLine((object) "" == (object) "");


Using Reflector I verified that string.Empty is assigned the empty literal,
"", in the class constructor (.cctor).  I also verified, through testing,
that interning works across assemblies; so I'm stumped here.

The earliest version of the framework that I have installed on my machine is
2.0, verified in Add or Remove Programs.  I also have 3.0 installed, if that
makes a difference.

Anyone know what's going on here?

--
Dave Sexton

Show quote
"Jon Shemitz" <j**@midnightbeach.com> wrote in message
news:4565F7B8.71B7A0BA@midnightbeach.com...
> Morten Wennevik wrote:
>
>> "" is easy to write, easy to read, and near impossible to misunderstand.
>> It will however create an object where String.Empty would not, but the ""
>> object is reused throughout the lifespawn of your application so the
>> difference can therefore be ignored.
>
> I was surprised to read that "" will create an object where
> String.Empty will not - surely String.Empty is just a static field
> that points to an interned "" constant?
>
> Sure enough, Reflector shows that String.Empty is implemented as
>
>  class string
>  {
>    static readonly string Empty = "";
>  }
>
> ... yet the below code shows that while both "" and String.Empty are
> interned, "" is not reference-equal to String.Empty. What gives? I
> thought the intern table was maintained across assembly boundaries, so
> it shouldn't matter that String.Empty comes from mscorlib.dll while ""
> comes from the app assembly.
>
> //
>
> using System;
>
> namespace StringEmptyTest
> {
>  class Program
>  {
>    static void Main(string[] args)
>    {
>      Console.WriteLine(Object.ReferenceEquals(String.Empty, ""));
>      Console.WriteLine(String.IsInterned("") != null);
>      Console.WriteLine(String.IsInterned(String.Empty) != null);
>      Console.ReadLine();
>    }
>  }
> }
>
>
> --
>
> .NET 2.0 for Delphi Programmers
> www.midnightbeach.com/.net
> What you need to know.
Author
29 Nov 2006 1:57 AM
clintonG
Sorry to go OT -- for a monet -- but you're able to load documentation at
msdn2.microsoft.com?
Quite a few people can not load pages at msdn2 for many weeks now and trying
to figure out why.

<%= Clinton Gallagher
         NET csgallagher AT metromilwaukee.com
         URL http://clintongallagher.metromilwaukee.com/
         MAP http://wikimapia.org/#y=43038073&x=-88043838&z=17&l=0&m=h

Show quote
"Dave Sexton" <dave@jwa[remove.this]online.com> wrote in message
news:%238GIy70EHHA.4024@TK2MSFTNGP04.phx.gbl...
> Hi Jon,
>
> Your example code has been bothering me - it should work, however it
> doesn't and I can't figure out why :p
>
> But if you think that's weird, check out the following documentation I
> found on MSDN:
>
> "String.Intern Method"
> http://msdn2.microsoft.com/en-us/library/system.string.intern.aspx
>
> <quote>
> Version Considerations
> Starting with the .NET Framework version 2.0, there is a behavioral change
> in the Intern method. In the following C# code sequence, the variable str1
> is assigned a reference to Empty, the variable str2 is assigned the
> reference to Empty that is returned by the Intern method, then the
> references contained in str1 and str2 are compared for equality.
>
> string str1 = String.Empty;
> string str2 = String.Intern(String.Empty);
> if ((object) str1) == ((object) str2) .
>
> In the .NET Framework version 1.1, str1 and str2 are not equal, but
> starting in the .NET Framework version 2.0, str1 and str2 are equal.
> </quote>
>
> Not in my test :|
>
> string str1 = String.Empty;
> string str2 = String.Intern(String.Empty);
>
> // false
> Console.WriteLine((object) str1 == (object) str2);
>
> // false
> Console.WriteLine((object) string.Empty == (object) "");
>
> // true
> Console.WriteLine((object) "" == (object) "");
>
>
> Using Reflector I verified that string.Empty is assigned the empty
> literal, "", in the class constructor (.cctor).  I also verified, through
> testing, that interning works across assemblies; so I'm stumped here.
>
> The earliest version of the framework that I have installed on my machine
> is 2.0, verified in Add or Remove Programs.  I also have 3.0 installed, if
> that makes a difference.
>
> Anyone know what's going on here?
>
> --
> Dave Sexton
>
> "Jon Shemitz" <j**@midnightbeach.com> wrote in message
> news:4565F7B8.71B7A0BA@midnightbeach.com...
>> Morten Wennevik wrote:
>>
>>> "" is easy to write, easy to read, and near impossible to misunderstand.
>>> It will however create an object where String.Empty would not, but the
>>> ""
>>> object is reused throughout the lifespawn of your application so the
>>> difference can therefore be ignored.
>>
>> I was surprised to read that "" will create an object where
>> String.Empty will not - surely String.Empty is just a static field
>> that points to an interned "" constant?
>>
>> Sure enough, Reflector shows that String.Empty is implemented as
>>
>>  class string
>>  {
>>    static readonly string Empty = "";
>>  }
>>
>> ... yet the below code shows that while both "" and String.Empty are
>> interned, "" is not reference-equal to String.Empty. What gives? I
>> thought the intern table was maintained across assembly boundaries, so
>> it shouldn't matter that String.Empty comes from mscorlib.dll while ""
>> comes from the app assembly.
>>
>> //
>>
>> using System;
>>
>> namespace StringEmptyTest
>> {
>>  class Program
>>  {
>>    static void Main(string[] args)
>>    {
>>      Console.WriteLine(Object.ReferenceEquals(String.Empty, ""));
>>      Console.WriteLine(String.IsInterned("") != null);
>>      Console.WriteLine(String.IsInterned(String.Empty) != null);
>>      Console.ReadLine();
>>    }
>>  }
>> }
>>
>>
>> --
>>
>> .NET 2.0 for Delphi Programmers
>> www.midnightbeach.com/.net
>> What you need to know.
>
>
Author
29 Nov 2006 2:23 AM
Dave Sexton
Hi,

I'm one of those people too - no secret here.

It works most of the time for me, but it can be painfully slow or not load
at all sometimes.  I assume they are making some major modifications to the
site.

Although, msdn.microsoft.com/library and the search itself seem to work just
fine, but once you click a search result that redirects you to msdn2, it's
20/80 ;)

--
Dave Sexton

Show quote
"clintonG" <csgallag***@REMOVETHISTEXTmetromilwaukee.com> wrote in message
news:urus1m1EHHA.4680@TK2MSFTNGP04.phx.gbl...
> Sorry to go OT -- for a monet -- but you're able to load documentation at
> msdn2.microsoft.com?
> Quite a few people can not load pages at msdn2 for many weeks now and
> trying to figure out why.
>
> <%= Clinton Gallagher
>         NET csgallagher AT metromilwaukee.com
>         URL http://clintongallagher.metromilwaukee.com/
>         MAP http://wikimapia.org/#y=43038073&x=-88043838&z=17&l=0&m=h
>
> "Dave Sexton" <dave@jwa[remove.this]online.com> wrote in message
> news:%238GIy70EHHA.4024@TK2MSFTNGP04.phx.gbl...
>> Hi Jon,
>>
>> Your example code has been bothering me - it should work, however it
>> doesn't and I can't figure out why :p
>>
>> But if you think that's weird, check out the following documentation I
>> found on MSDN:
>>
>> "String.Intern Method"
>> http://msdn2.microsoft.com/en-us/library/system.string.intern.aspx
>>
>> <quote>
>> Version Considerations
>> Starting with the .NET Framework version 2.0, there is a behavioral
>> change in the Intern method. In the following C# code sequence, the
>> variable str1 is assigned a reference to Empty, the variable str2 is
>> assigned the reference to Empty that is returned by the Intern method,
>> then the references contained in str1 and str2 are compared for equality.
>>
>> string str1 = String.Empty;
>> string str2 = String.Intern(String.Empty);
>> if ((object) str1) == ((object) str2) .
>>
>> In the .NET Framework version 1.1, str1 and str2 are not equal, but
>> starting in the .NET Framework version 2.0, str1 and str2 are equal.
>> </quote>
>>
>> Not in my test :|
>>
>> string str1 = String.Empty;
>> string str2 = String.Intern(String.Empty);
>>
>> // false
>> Console.WriteLine((object) str1 == (object) str2);
>>
>> // false
>> Console.WriteLine((object) string.Empty == (object) "");
>>
>> // true
>> Console.WriteLine((object) "" == (object) "");
>>
>>
>> Using Reflector I verified that string.Empty is assigned the empty
>> literal, "", in the class constructor (.cctor).  I also verified, through
>> testing, that interning works across assemblies; so I'm stumped here.
>>
>> The earliest version of the framework that I have installed on my machine
>> is 2.0, verified in Add or Remove Programs.  I also have 3.0 installed,
>> if that makes a difference.
>>
>> Anyone know what's going on here?
>>
>> --
>> Dave Sexton
>>
>> "Jon Shemitz" <j**@midnightbeach.com> wrote in message
>> news:4565F7B8.71B7A0BA@midnightbeach.com...
>>> Morten Wennevik wrote:
>>>
>>>> "" is easy to write, easy to read, and near impossible to
>>>> misunderstand.
>>>> It will however create an object where String.Empty would not, but the
>>>> ""
>>>> object is reused throughout the lifespawn of your application so the
>>>> difference can therefore be ignored.
>>>
>>> I was surprised to read that "" will create an object where
>>> String.Empty will not - surely String.Empty is just a static field
>>> that points to an interned "" constant?
>>>
>>> Sure enough, Reflector shows that String.Empty is implemented as
>>>
>>>  class string
>>>  {
>>>    static readonly string Empty = "";
>>>  }
>>>
>>> ... yet the below code shows that while both "" and String.Empty are
>>> interned, "" is not reference-equal to String.Empty. What gives? I
>>> thought the intern table was maintained across assembly boundaries, so
>>> it shouldn't matter that String.Empty comes from mscorlib.dll while ""
>>> comes from the app assembly.
>>>
>>> //
>>>
>>> using System;
>>>
>>> namespace StringEmptyTest
>>> {
>>>  class Program
>>>  {
>>>    static void Main(string[] args)
>>>    {
>>>      Console.WriteLine(Object.ReferenceEquals(String.Empty, ""));
>>>      Console.WriteLine(String.IsInterned("") != null);
>>>      Console.WriteLine(String.IsInterned(String.Empty) != null);
>>>      Console.ReadLine();
>>>    }
>>>  }
>>> }
>>>
>>>
>>> --
>>>
>>> .NET 2.0 for Delphi Programmers
>>> www.midnightbeach.com/.net
>>> What you need to know.
>>
>>
>
>
Author
2 Dec 2006 5:13 PM
clintonG
Misery loves company ;-)

<%= Clinton

Show quote
"Dave Sexton" <dave@jwa[remove.this]online.com> wrote in message
news:Ov4ii11EHHA.4740@TK2MSFTNGP03.phx.gbl...
> Hi,
>
> I'm one of those people too - no secret here.
>
> It works most of the time for me, but it can be painfully slow or not load
> at all sometimes.  I assume they are making some major modifications to
> the site.
>
> Although, msdn.microsoft.com/library and the search itself seem to work
> just fine, but once you click a search result that redirects you to msdn2,
> it's 20/80 ;)
>
> --
> Dave Sexton
>
> "clintonG" <csgallag***@REMOVETHISTEXTmetromilwaukee.com> wrote in message
> news:urus1m1EHHA.4680@TK2MSFTNGP04.phx.gbl...
>> Sorry to go OT -- for a monet -- but you're able to load documentation at
>> msdn2.microsoft.com?
>> Quite a few people can not load pages at msdn2 for many weeks now and
>> trying to figure out why.
>>
>> <%= Clinton Gallagher
>>         NET csgallagher AT metromilwaukee.com
>>         URL http://clintongallagher.metromilwaukee.com/
>>         MAP http://wikimapia.org/#y=43038073&x=-88043838&z=17&l=0&m=h
>>
>> "Dave Sexton" <dave@jwa[remove.this]online.com> wrote in message
>> news:%238GIy70EHHA.4024@TK2MSFTNGP04.phx.gbl...
>>> Hi Jon,
>>>
>>> Your example code has been bothering me - it should work, however it
>>> doesn't and I can't figure out why :p
>>>
>>> But if you think that's weird, check out the following documentation I
>>> found on MSDN:
>>>
>>> "String.Intern Method"
>>> http://msdn2.microsoft.com/en-us/library/system.string.intern.aspx
>>>
>>> <quote>
>>> Version Considerations
>>> Starting with the .NET Framework version 2.0, there is a behavioral
>>> change in the Intern method. In the following C# code sequence, the
>>> variable str1 is assigned a reference to Empty, the variable str2 is
>>> assigned the reference to Empty that is returned by the Intern method,
>>> then the references contained in str1 and str2 are compared for
>>> equality.
>>>
>>> string str1 = String.Empty;
>>> string str2 = String.Intern(String.Empty);
>>> if ((object) str1) == ((object) str2) .
>>>
>>> In the .NET Framework version 1.1, str1 and str2 are not equal, but
>>> starting in the .NET Framework version 2.0, str1 and str2 are equal.
>>> </quote>
>>>
>>> Not in my test :|
>>>
>>> string str1 = String.Empty;
>>> string str2 = String.Intern(String.Empty);
>>>
>>> // false
>>> Console.WriteLine((object) str1 == (object) str2);
>>>
>>> // false
>>> Console.WriteLine((object) string.Empty == (object) "");
>>>
>>> // true
>>> Console.WriteLine((object) "" == (object) "");
>>>
>>>
>>> Using Reflector I verified that string.Empty is assigned the empty
>>> literal, "", in the class constructor (.cctor).  I also verified,
>>> through testing, that interning works across assemblies; so I'm stumped
>>> here.
>>>
>>> The earliest version of the framework that I have installed on my
>>> machine is 2.0, verified in Add or Remove Programs.  I also have 3.0
>>> installed, if that makes a difference.
>>>
>>> Anyone know what's going on here?
>>>
>>> --
>>> Dave Sexton
>>>
>>> "Jon Shemitz" <j**@midnightbeach.com> wrote in message
>>> news:4565F7B8.71B7A0BA@midnightbeach.com...
>>>> Morten Wennevik wrote:
>>>>
>>>>> "" is easy to write, easy to read, and near impossible to
>>>>> misunderstand.
>>>>> It will however create an object where String.Empty would not, but the
>>>>> ""
>>>>> object is reused throughout the lifespawn of your application so the
>>>>> difference can therefore be ignored.
>>>>
>>>> I was surprised to read that "" will create an object where
>>>> String.Empty will not - surely String.Empty is just a static field
>>>> that points to an interned "" constant?
>>>>
>>>> Sure enough, Reflector shows that String.Empty is implemented as
>>>>
>>>>  class string
>>>>  {
>>>>    static readonly string Empty = "";
>>>>  }
>>>>
>>>> ... yet the below code shows that while both "" and String.Empty are
>>>> interned, "" is not reference-equal to String.Empty. What gives? I
>>>> thought the intern table was maintained across assembly boundaries, so
>>>> it shouldn't matter that String.Empty comes from mscorlib.dll while ""
>>>> comes from the app assembly.
>>>>
>>>> //
>>>>
>>>> using System;
>>>>
>>>> namespace StringEmptyTest
>>>> {
>>>>  class Program
>>>>  {
>>>>    static void Main(string[] args)
>>>>    {
>>>>      Console.WriteLine(Object.ReferenceEquals(String.Empty, ""));
>>>>      Console.WriteLine(String.IsInterned("") != null);
>>>>      Console.WriteLine(String.IsInterned(String.Empty) != null);
>>>>      Console.ReadLine();
>>>>    }
>>>>  }
>>>> }
>>>>
>>>>
>>>> --
>>>>
>>>> .NET 2.0 for Delphi Programmers
>>>> www.midnightbeach.com/.net
>>>> What you need to know.
>>>
>>>
>>
>>
>
>
Author
2 Dec 2006 5:39 PM
Dave Sexton
Hi Clinton,

:)

Even stranger, FireFox appears to be slower than IE7 when loading msdn2 now
(when it works :)

--
Dave Sexton

Show quote
"clintonG" <csgallag***@REMOVETHISTEXTmetromilwaukee.com> wrote in message
news:OW7fnUjFHHA.5000@TK2MSFTNGP03.phx.gbl...
> Misery loves company ;-)
>
> <%= Clinton
>
> "Dave Sexton" <dave@jwa[remove.this]online.com> wrote in message
> news:Ov4ii11EHHA.4740@TK2MSFTNGP03.phx.gbl...
>> Hi,
>>
>> I'm one of those people too - no secret here.
>>
>> It works most of the time for me, but it can be painfully slow or not
>> load at all sometimes.  I assume they are making some major modifications
>> to the site.
>>
>> Although, msdn.microsoft.com/library and the search itself seem to work
>> just fine, but once you click a search result that redirects you to
>> msdn2, it's 20/80 ;)
>>
>> --
>> Dave Sexton
>>
>> "clintonG" <csgallag***@REMOVETHISTEXTmetromilwaukee.com> wrote in
>> message news:urus1m1EHHA.4680@TK2MSFTNGP04.phx.gbl...
>>> Sorry to go OT -- for a monet -- but you're able to load documentation
>>> at msdn2.microsoft.com?
>>> Quite a few people can not load pages at msdn2 for many weeks now and
>>> trying to figure out why.
>>>
>>> <%= Clinton Gallagher
>>>         NET csgallagher AT metromilwaukee.com
>>>         URL http://clintongallagher.metromilwaukee.com/
>>>         MAP http://wikimapia.org/#y=43038073&x=-88043838&z=17&l=0&m=h
>>>
>>> "Dave Sexton" <dave@jwa[remove.this]online.com> wrote in message
>>> news:%238GIy70EHHA.4024@TK2MSFTNGP04.phx.gbl...
>>>> Hi Jon,
>>>>
>>>> Your example code has been bothering me - it should work, however it
>>>> doesn't and I can't figure out why :p
>>>>
>>>> But if you think that's weird, check out the following documentation I
>>>> found on MSDN:
>>>>
>>>> "String.Intern Method"
>>>> http://msdn2.microsoft.com/en-us/library/system.string.intern.aspx
>>>>
>>>> <quote>
>>>> Version Considerations
>>>> Starting with the .NET Framework version 2.0, there is a behavioral
>>>> change in the Intern method. In the following C# code sequence, the
>>>> variable str1 is assigned a reference to Empty, the variable str2 is
>>>> assigned the reference to Empty that is returned by the Intern method,
>>>> then the references contained in str1 and str2 are compared for
>>>> equality.
>>>>
>>>> string str1 = String.Empty;
>>>> string str2 = String.Intern(String.Empty);
>>>> if ((object) str1) == ((object) str2) .
>>>>
>>>> In the .NET Framework version 1.1, str1 and str2 are not equal, but
>>>> starting in the .NET Framework version 2.0, str1 and str2 are equal.
>>>> </quote>
>>>>
>>>> Not in my test :|
>>>>
>>>> string str1 = String.Empty;
>>>> string str2 = String.Intern(String.Empty);
>>>>
>>>> // false
>>>> Console.WriteLine((object) str1 == (object) str2);
>>>>
>>>> // false
>>>> Console.WriteLine((object) string.Empty == (object) "");
>>>>
>>>> // true
>>>> Console.WriteLine((object) "" == (object) "");
>>>>
>>>>
>>>> Using Reflector I verified that string.Empty is assigned the empty
>>>> literal, "", in the class constructor (.cctor).  I also verified,
>>>> through testing, that interning works across assemblies; so I'm stumped
>>>> here.
>>>>
>>>> The earliest version of the framework that I have installed on my
>>>> machine is 2.0, verified in Add or Remove Programs.  I also have 3.0
>>>> installed, if that makes a difference.
>>>>
>>>> Anyone know what's going on here?
>>>>
>>>> --
>>>> Dave Sexton
>>>>
>>>> "Jon Shemitz" <j**@midnightbeach.com> wrote in message
>>>> news:4565F7B8.71B7A0BA@midnightbeach.com...
>>>>> Morten Wennevik wrote:
>>>>>
>>>>>> "" is easy to write, easy to read, and near impossible to
>>>>>> misunderstand.
>>>>>> It will however create an object where String.Empty would not, but
>>>>>> the ""
>>>>>> object is reused throughout the lifespawn of your application so the
>>>>>> difference can therefore be ignored.
>>>>>
>>>>> I was surprised to read that "" will create an object where
>>>>> String.Empty will not - surely String.Empty is just a static field
>>>>> that points to an interned "" constant?
>>>>>
>>>>> Sure enough, Reflector shows that String.Empty is implemented as
>>>>>
>>>>>  class string
>>>>>  {
>>>>>    static readonly string Empty = "";
>>>>>  }
>>>>>
>>>>> ... yet the below code shows that while both "" and String.Empty are
>>>>> interned, "" is not reference-equal to String.Empty. What gives? I
>>>>> thought the intern table was maintained across assembly boundaries, so
>>>>> it shouldn't matter that String.Empty comes from mscorlib.dll while ""
>>>>> comes from the app assembly.
>>>>>
>>>>> //
>>>>>
>>>>> using System;
>>>>>
>>>>> namespace StringEmptyTest
>>>>> {
>>>>>  class Program
>>>>>  {
>>>>>    static void Main(string[] args)
>>>>>    {
>>>>>      Console.WriteLine(Object.ReferenceEquals(String.Empty, ""));
>>>>>      Console.WriteLine(String.IsInterned("") != null);
>>>>>      Console.WriteLine(String.IsInterned(String.Empty) != null);
>>>>>      Console.ReadLine();
>>>>>    }
>>>>>  }
>>>>> }
>>>>>
>>>>>
>>>>> --
>>>>>
>>>>> .NET 2.0 for Delphi Programmers
>>>>> www.midnightbeach.com/.net
>>>>> What you need to know.
>>>>
>>>>
>>>
>>>
>>
>>
>
>
Author
20 Dec 2006 7:25 PM
clintonG
I urge you to respond to my recent news article posted in several Microsoft
newsgroups related to MSDN and ASP.NET development. The subject is

"For Microsoft Partners and Customers Who Can't Download or Access MSDN2..."

Take your own stance of course but please let your voice be heard about
these server failures.

<%= Clinton Gallagher
         NET csgallagher AT metromilwaukee.com
         URL http://clintongallagher.metromilwaukee.com/
         MAP http://wikimapia.org/#y=43038073&x=-88043838&z=17&l=0&m=h




Show quote
"Dave Sexton" <dave@jwa[remove.this]online.com> wrote in message
news:um8cijjFHHA.5004@TK2MSFTNGP03.phx.gbl...
> Hi Clinton,
>
> :)
>
> Even stranger, FireFox appears to be slower than IE7 when loading msdn2
> now (when it works :)
>
> --
> Dave Sexton
>
> "clintonG" <csgallag***@REMOVETHISTEXTmetromilwaukee.com> wrote in message
> news:OW7fnUjFHHA.5000@TK2MSFTNGP03.phx.gbl...
>> Misery loves company ;-)
>>
>> <%= Clinton
>>
>> "Dave Sexton" <dave@jwa[remove.this]online.com> wrote in message
>> news:Ov4ii11EHHA.4740@TK2MSFTNGP03.phx.gbl...
>>> Hi,
>>>
>>> I'm one of those people too - no secret here.
>>>
>>> It works most of the time for me, but it can be painfully slow or not
>>> load at all sometimes.  I assume they are making some major
>>> modifications to the site.
>>>
>>> Although, msdn.microsoft.com/library and the search itself seem to work
>>> just fine, but once you click a search result that redirects you to
>>> msdn2, it's 20/80 ;)
>>>
>>> --
>>> Dave Sexton
>>>
>>> "clintonG" <csgallag***@REMOVETHISTEXTmetromilwaukee.com> wrote in
>>> message news:urus1m1EHHA.4680@TK2MSFTNGP04.phx.gbl...
>>>> Sorry to go OT -- for a monet -- but you're able to load documentation
>>>> at msdn2.microsoft.com?
>>>> Quite a few people can not load pages at msdn2 for many weeks now and
>>>> trying to figure out why.
>>>>
>>>> <%= Clinton Gallagher
>>>>         NET csgallagher AT metromilwaukee.com
>>>>         URL http://clintongallagher.metromilwaukee.com/
>>>>         MAP http://wikimapia.org/#y=43038073&x=-88043838&z=17&l=0&m=h
>>>>
>>>> "Dave Sexton" <dave@jwa[remove.this]online.com> wrote in message
>>>> news:%238GIy70EHHA.4024@TK2MSFTNGP04.phx.gbl...
>>>>> Hi Jon,
>>>>>
>>>>> Your example code has been bothering me - it should work, however it
>>>>> doesn't and I can't figure out why :p
>>>>>
>>>>> But if you think that's weird, check out the following documentation I
>>>>> found on MSDN:
>>>>>
>>>>> "String.Intern Method"
>>>>> http://msdn2.microsoft.com/en-us/library/system.string.intern.aspx
>>>>>
>>>>> <quote>
>>>>> Version Considerations
>>>>> Starting with the .NET Framework version 2.0, there is a behavioral
>>>>> change in the Intern method. In the following C# code sequence, the
>>>>> variable str1 is assigned a reference to Empty, the variable str2 is
>>>>> assigned the reference to Empty that is returned by the Intern method,
>>>>> then the references contained in str1 and str2 are compared for
>>>>> equality.
>>>>>
>>>>> string str1 = String.Empty;
>>>>> string str2 = String.Intern(String.Empty);
>>>>> if ((object) str1) == ((object) str2) .
>>>>>
>>>>> In the .NET Framework version 1.1, str1 and str2 are not equal, but
>>>>> starting in the .NET Framework version 2.0, str1 and str2 are equal.
>>>>> </quote>
>>>>>
>>>>> Not in my test :|
>>>>>
>>>>> string str1 = String.Empty;
>>>>> string str2 = String.Intern(String.Empty);
>>>>>
>>>>> // false
>>>>> Console.WriteLine((object) str1 == (object) str2);
>>>>>
>>>>> // false
>>>>> Console.WriteLine((object) string.Empty == (object) "");
>>>>>
>>>>> // true
>>>>> Console.WriteLine((object) "" == (object) "");
>>>>>
>>>>>
>>>>> Using Reflector I verified that string.Empty is assigned the empty
>>>>> literal, "", in the class constructor (.cctor).  I also verified,
>>>>> through testing, that interning works across assemblies; so I'm
>>>>> stumped here.
>>>>>
>>>>> The earliest version of the framework that I have installed on my
>>>>> machine is 2.0, verified in Add or Remove Programs.  I also have 3.0
>>>>> installed, if that makes a difference.
>>>>>
>>>>> Anyone know what's going on here?
>>>>>
>>>>> --
>>>>> Dave Sexton
>>>>>
>>>>> "Jon Shemitz" <j**@midnightbeach.com> wrote in message
>>>>> news:4565F7B8.71B7A0BA@midnightbeach.com...
>>>>>> Morten Wennevik wrote:
>>>>>>
>>>>>>> "" is easy to write, easy to read, and near impossible to
>>>>>>> misunderstand.
>>>>>>> It will however create an object where String.Empty would not, but
>>>>>>> the ""
>>>>>>> object is reused throughout the lifespawn of your application so the
>>>>>>> difference can therefore be ignored.
>>>>>>
>>>>>> I was surprised to read that "" will create an object where
>>>>>> String.Empty will not - surely String.Empty is just a static field
>>>>>> that points to an interned "" constant?
>>>>>>
>>>>>> Sure enough, Reflector shows that String.Empty is implemented as
>>>>>>
>>>>>>  class string
>>>>>>  {
>>>>>>    static readonly string Empty = "";
>>>>>>  }
>>>>>>
>>>>>> ... yet the below code shows that while both "" and String.Empty are
>>>>>> interned, "" is not reference-equal to String.Empty. What gives? I
>>>>>> thought the intern table was maintained across assembly boundaries,
>>>>>> so
>>>>>> it shouldn't matter that String.Empty comes from mscorlib.dll while
>>>>>> ""
>>>>>> comes from the app assembly.
>>>>>>
>>>>>> //
>>>>>>
>>>>>> using System;
>>>>>>
>>>>>> namespace StringEmptyTest
>>>>>> {
>>>>>>  class Program
>>>>>>  {
>>>>>>    static void Main(string[] args)
>>>>>>    {
>>>>>>      Console.WriteLine(Object.ReferenceEquals(String.Empty, ""));
>>>>>>      Console.WriteLine(String.IsInterned("") != null);
>>>>>>      Console.WriteLine(String.IsInterned(String.Empty) != null);
>>>>>>      Console.ReadLine();
>>>>>>    }
>>>>>>  }
>>>>>> }
>>>>>>
>>>>>>
>>>>>> --
>>>>>>
>>>>>> .NET 2.0 for Delphi Programmers
>>>>>> www.midnightbeach.com/.net
>>>>>> What you need to know.
>>>>>
>>>>>
>>>>
>>>>
>>>
>>>
>>
>>
>
>
Author
23 Nov 2006 7:26 PM
Jon Skeet [C# MVP]
<anoni***@hotmail.com> wrote:
> In the past I always used "" everywhere for empty string in my code
> without a problem.
>
> Now, do you think I should use String.Empty instead of "" (at all
> times) ?

Which do you find easier to read? That's pretty much the only
difference of any significance, IMO.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet   Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Author
28 Nov 2006 12:14 AM
Gabriel Lozano-Morán
And what happens if string interning is disabled? Doesn't this mean that
each time you have a "" in your code that you will have the overhead of
allocating memory on the heap and creating a new string object?

Gabriel

Show quote
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MPG.1fd006413738da3298d655@msnews.microsoft.com...
> <anoni***@hotmail.com> wrote:
>> In the past I always used "" everywhere for empty string in my code
>> without a problem.
>>
>> Now, do you think I should use String.Empty instead of "" (at all
>> times) ?
>
> Which do you find easier to read? That's pretty much the only
> difference of any significance, IMO.
>
> --
> Jon Skeet - <sk***@pobox.com>
> http://www.pobox.com/~skeet   Blog: http://www.msmvps.com/jon.skeet
> If replying to the group, please do not mail me too
Author
28 Nov 2006 7:35 AM
Jon Skeet [C# MVP]
Gabriel Lozano-Morán <ab***@frontbridge.com> wrote:
> And what happens if string interning is disabled? Doesn't this mean that
> each time you have a "" in your code that you will have the overhead of
> allocating memory on the heap and creating a new string object?

String interning isn't something you can enable or disable, as far as
I'm aware - and at that point, the C# language specification is being
violated. I don't alter my programming style in order to suit
situations like that - it's like changing your style to suit a
situation where garbage collection doesn't occur.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet   Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Author
28 Nov 2006 12:54 PM
Gabriel Lozano-Morán
See:
http://msdn2.microsoft.com/en-us/library/system.runtime.compilerservices.compilationrelaxationsattribute.aspx
http://msdn2.microsoft.com/en-us/library/system.runtime.compilerservices.compilationrelaxations.aspx

Gabriel Lozano-Morán


"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MPG.1fd5f739350795f798d66e@msnews.microsoft.com...
Gabriel Lozano-Morán <ab***@frontbridge.com> wrote:
> And what happens if string interning is disabled? Doesn't this mean that
> each time you have a "" in your code that you will have the overhead of
> allocating memory on the heap and creating a new string object?

String interning isn't something you can enable or disable, as far as
I'm aware - and at that point, the C# language specification is being
violated. I don't alter my programming style in order to suit
situations like that - it's like changing your style to suit a
situation where garbage collection doesn't occur.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet   Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Author
28 Nov 2006 7:44 PM
Jon Skeet [C# MVP]
Gabriel Lozano-Morán <ab***@frontbridge.com> wrote:
> See:
> http://msdn2.microsoft.com/en-us/library/system.runtime.compilerservi
> ces.compilationrelaxationsattribute.aspx

How bizarre. Using that would certainly mean you were no longer using a
language which conformed to the C# language spec. However, you would
have to *explicitly* use that attribute, so again I can't see that it's
actually a consideration to think about in normal coding.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet   Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Author
28 Nov 2006 10:45 PM
Mattias Sjögren
>How bizarre. Using that would certainly mean you were no longer using a
>language which conformed to the C# language spec. However, you would
>have to *explicitly* use that attribute

Actually the C# 2.0 compiler adds this attribute to all assemblies,
unless you explicitly specify otherwise.

Which part of the spec do you mean this would violate? I know that
previous compiler versions sometimes relied on interning to implement
the switch statement for strings, but that doesn't seem to be the case
anymore.


Mattias

--
Mattias Sjögren [C# MVP]  mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Author
28 Nov 2006 11:18 PM
Jon Skeet [C# MVP]
Mattias Sjögren <mattias.dont.want.spam@mvps.org> wrote:
> >How bizarre. Using that would certainly mean you were no longer using a
> >language which conformed to the C# language spec. However, you would
> >have to *explicitly* use that attribute
>
> Actually the C# 2.0 compiler adds this attribute to all assemblies,
> unless you explicitly specify otherwise.

Yikes - you're right. Interesting that it doesn't seem to have the
indicated effect. Here's a sample program:

using System;
using System.Diagnostics;

class Test1
{
    public static string Empty = "";
}

class Test2
{
    public static string Empty = "";
}

class Test
{
    static void Main()
    {
        string s1 = Test1.Empty;
        string s2 = Test2.Empty;
        Console.WriteLine (object.ReferenceEquals(s1, s2));
    }
}

That prints "True" on my box, which will only be true if the strings
are interned. Printing string.IsInterned("x") shows that being interned
too.

Odd. I'm intrigued now...

> Which part of the spec do you mean this would violate? I know that
> previous compiler versions sometimes relied on interning to implement
> the switch statement for strings, but that doesn't seem to be the case
> anymore.

From
http://www.jaggersoft.com/csharp_standard/9.4.4.5.htm#string-literal

<quote>
Each string literal does not necessarily result in a new string
instance. When two or more string literals that are equivalent
according to the string equality operator (§14.9.7), appear in the same
assembly, these string literals refer to the same string instance.
</quote>

(I'll have to look at how strings are switched now, too. So much to
look at, so little time...)

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet   Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Author
28 Nov 2006 11:25 PM
Dave Sexton
Hi Jon,

Apparently, CompilationRelaxations.NoStringInterning only disables string
interning for the NGEN utility.  This setting is automatically applied on
all assemblies compiled by the C# 2.0 compiler, as Mattias already
mentioned, and as you've pointed out Interning is certainly not disabled in
2.0 :)

The documentation Gabriel has cited is definitely misleading and should be
updated.  I don't believe that C# or .NET provides the ability to disable
string interning in code.

"Starting with the .NET Framework version 2.0, you can override the use of
the intern pool when you use the Native Image Generator (Ngen.exe) to
install an assembly to the native image cache on a local computer. For more
information, see Performance Considerations in the Remarks section for the
Intern property."   (and by "property" I think they mean "method" :)

"String.IsInterned Method"
http://msdn2.microsoft.com/en-us/library/system.string.isinterned.aspx

"The .NET Framework version 2.0 introduces the
CompilationRelaxations.NoStringInterning enumeration member. The
NoStringInterning member marks an assembly as not requiring string-literal
interning. You can apply NoStringInterning to an assembly using the
CompilationRelaxationsAttribute attribute. When you use the Native Image
Generator (Ngen.exe) to install that assembly to the native image cache on
the local computer, string interning is not used."

"String.Intern Method"
http://msdn2.microsoft.com/en-us/library/system.string.intern(vs.80).aspx

--
Dave Sexton

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MPG.1fd6d4262968b8f098d677@msnews.microsoft.com...
Mattias Sjögren <mattias.dont.want.spam@mvps.org> wrote:
> >How bizarre. Using that would certainly mean you were no longer using a
> >language which conformed to the C# language spec. However, you would
> >have to *explicitly* use that attribute
>
> Actually the C# 2.0 compiler adds this attribute to all assemblies,
> unless you explicitly specify otherwise.

Yikes - you're right. Interesting that it doesn't seem to have the
indicated effect. Here's a sample program:

using System;
using System.Diagnostics;

class Test1
{
    public static string Empty = "";
}

class Test2
{
    public static string Empty = "";
}

class Test
{
    static void Main()
    {
        string s1 = Test1.Empty;
        string s2 = Test2.Empty;
        Console.WriteLine (object.ReferenceEquals(s1, s2));
    }
}

That prints "True" on my box, which will only be true if the strings
are interned. Printing string.IsInterned("x") shows that being interned
too.

Odd. I'm intrigued now...

> Which part of the spec do you mean this would violate? I know that
> previous compiler versions sometimes relied on interning to implement
> the switch statement for strings, but that doesn't seem to be the case
> anymore.

From
http://www.jaggersoft.com/csharp_standard/9.4.4.5.htm#string-literal

<quote>
Each string literal does not necessarily result in a new string
instance. When two or more string literals that are equivalent
according to the string equality operator (§14.9.7), appear in the same
assembly, these string literals refer to the same string instance.
</quote>

(I'll have to look at how strings are switched now, too. So much to
look at, so little time...)

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet   Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Author
29 Nov 2006 3:45 AM
Gabriel Lozano-Morán
Correct at the moment it is only for NGEN-ed assemblies but if I am not
mistaken it is possible that in future versions it will be possible to
disable the intern pool imho that's the reason why the documentation might
seem misleading. Personally I have never understand the need for string
interning and the overhead that comes with it because how many times will
you have two or more exact string literals?

Gabriel

Show quote
"Dave Sexton" <dave@jwa[remove.this]online.com> wrote in message
news:urSCZS0EHHA.5028@TK2MSFTNGP03.phx.gbl...
> Hi Jon,
>
> Apparently, CompilationRelaxations.NoStringInterning only disables string
> interning for the NGEN utility.  This setting is automatically applied on
> all assemblies compiled by the C# 2.0 compiler, as Mattias already
> mentioned, and as you've pointed out Interning is certainly not disabled
> in 2.0 :)
>
> The documentation Gabriel has cited is definitely misleading and should be
> updated.  I don't believe that C# or .NET provides the ability to disable
> string interning in code.
>
> "Starting with the .NET Framework version 2.0, you can override the use of
> the intern pool when you use the Native Image Generator (Ngen.exe) to
> install an assembly to the native image cache on a local computer. For
> more information, see Performance Considerations in the Remarks section
> for the Intern property."   (and by "property" I think they mean "method"
> :)
>
> "String.IsInterned Method"
> http://msdn2.microsoft.com/en-us/library/system.string.isinterned.aspx
>
> "The .NET Framework version 2.0 introduces the
> CompilationRelaxations.NoStringInterning enumeration member. The
> NoStringInterning member marks an assembly as not requiring string-literal
> interning. You can apply NoStringInterning to an assembly using the
> CompilationRelaxationsAttribute attribute. When you use the Native Image
> Generator (Ngen.exe) to install that assembly to the native image cache on
> the local computer, string interning is not used."
>
> "String.Intern Method"
> http://msdn2.microsoft.com/en-us/library/system.string.intern(vs.80).aspx
>
> --
> Dave Sexton
>
> "Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
> news:MPG.1fd6d4262968b8f098d677@msnews.microsoft.com...
> Mattias Sjögren <mattias.dont.want.spam@mvps.org> wrote:
>> >How bizarre. Using that would certainly mean you were no longer using a
>> >language which conformed to the C# language spec. However, you would
>> >have to *explicitly* use that attribute
>>
>> Actually the C# 2.0 compiler adds this attribute to all assemblies,
>> unless you explicitly specify otherwise.
>
> Yikes - you're right. Interesting that it doesn't seem to have the
> indicated effect. Here's a sample program:
>
> using System;
> using System.Diagnostics;
>
> class Test1
> {
>    public static string Empty = "";
> }
>
> class Test2
> {
>    public static string Empty = "";
> }
>
> class Test
> {
>    static void Main()
>    {
>        string s1 = Test1.Empty;
>        string s2 = Test2.Empty;
>        Console.WriteLine (object.ReferenceEquals(s1, s2));
>    }
> }
>
> That prints "True" on my box, which will only be true if the strings
> are interned. Printing string.IsInterned("x") shows that being interned
> too.
>
> Odd. I'm intrigued now...
>
>> Which part of the spec do you mean this would violate? I know that
>> previous compiler versions sometimes relied on interning to implement
>> the switch statement for strings, but that doesn't seem to be the case
>> anymore.
>
> From
> http://www.jaggersoft.com/csharp_standard/9.4.4.5.htm#string-literal
>
> <quote>
> Each string literal does not necessarily result in a new string
> instance. When two or more string literals that are equivalent
> according to the string equality operator (§14.9.7), appear in the same
> assembly, these string literals refer to the same string instance.
> </quote>
>
> (I'll have to look at how strings are switched now, too. So much to
> look at, so little time...)
>
> --
> Jon Skeet - <sk***@pobox.com>
> http://www.pobox.com/~skeet   Blog: http://www.msmvps.com/jon.skeet
> If replying to the group, please do not mail me too
>
Author
29 Nov 2006 7:29 AM
Jon Shemitz
"Gabriel Lozano-Morán" wrote:
>
> Correct at the moment it is only for NGEN-ed assemblies but if I am not
> mistaken it is possible that in future versions it will be possible to
> disable the intern pool imho that's the reason why the documentation might
> seem misleading. Personally I have never understand the need for string
> interning and the overhead that comes with it because how many times will
> you have two or more exact string literals?

Depends on how much HTML/XML you're generating, I guess.

--

..NET 2.0 for Delphi Programmers
www.midnightbeach.com/.net
What you need to know.
Author
28 Nov 2006 11:28 PM
Jon Shemitz
"Mattias Sjögren" wrote:

> Actually the C# 2.0 compiler adds this attribute to all assemblies,
> unless you explicitly specify otherwise.
>
> Which part of the spec do you mean this would violate? I know that
> previous compiler versions sometimes relied on interning to implement
> the switch statement for strings, but that doesn't seem to be the case
> anymore.

That's news to me, but a quick test shows that you're right.

That's rather strange - I wonder if they found that the cost of
interning switch input strings was greater than the savings from using
ReferenceEquals instead of Equals (when comparing the input string to
the case tags).

--

..NET 2.0 for Delphi Programmers
www.midnightbeach.com/.net
What you need to know.
Author
28 Nov 2006 7:38 PM
Chris Mullins
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote
> > And what happens if string interning is disabled?

> String interning isn't something you can enable or disable, as far as
> I'm aware - and at that point, the C# language specification is being
> violated.

You can't disable it. At least not that I was able to find, and I looked for
quite a while.

I wrote up a blog entry on my findings with string interning and when /
where it can save memory (at least in the case i'm worried about):
http://www.coversant.com/dotnetnuke/Default.aspx?tabid=88&EntryID=24

--
Chris Mullins, MCSD.NET, MCPD:Enterprise
http://www.coversant.net/blogs/cmullins
Author
28 Nov 2006 8:32 PM
Chris Mullins
<anoni***@hotmail.com> wrote:
> In the past I always used "" everywhere for empty string in my code
> without a problem.
>
> Now, do you think I should use String.Empty instead of "" (at all
> times) ?

From the Blog at:
http://blogs.msdn.com/brada/archive/2003/04/22/49997.aspx

> "" actually creates an object, it will likely be
> pulled out of the string intern pool, but still.
> while String.Empty creates no object.
> so if you are really looking for ultimately
> in memory efficiency, I suggest String.Empty.

So there ya have it. String.Empty is obviously a zillion times better than
"". :)

In all honesty though, I don't think it ever really matters. Certainly not
in any cases I've ever come across. I use string.empty, because I dislike
the look of "".

--
Chris Mullins, MCSD.NET, MCPD:Enterprise
http://www.coversant.net/blogs/cmullins
Author
28 Nov 2006 8:47 PM
Dave Sexton
Hi,

I use string.Empty because that's what everyone I talked to had told me
since the original framework beta.

Personally, I don't really care either way now, but it's just a habit.

If I could shake the OCD involved I might be able to start using "" instead,
which seems cleaner to me ;)

--
Dave Sexton

<anoni***@hotmail.com> wrote in message
Show quote
news:1164275826.495190.9500@j72g2000cwa.googlegroups.com...
> In the past I always used "" everywhere for empty string in my code
> without a problem.
>
> Now, do you think I should use String.Empty instead of "" (at all
> times) ?
>
> Let me know your thoughts.
>
Author
28 Nov 2006 9:27 PM
Gabriel Lozano-Morán
I personally prefer string.Empty over "" in code. It is just a matter of
flavor but it can be a good thing to make it a guideline whether or not you
to use "" vs string.Empty for the team.

Gabriel Lozano-Morán

Show quote
"Dave Sexton" <dave@jwa[remove.this]online.com> wrote in message
news:ex1125yEHHA.3820@TK2MSFTNGP02.phx.gbl...
> Hi,
>
> I use string.Empty because that's what everyone I talked to had told me
> since the original framework beta.
>
> Personally, I don't really care either way now, but it's just a habit.
>
> If I could shake the OCD involved I might be able to start using ""
> instead, which seems cleaner to me ;)
>
> --
> Dave Sexton
>
> <anoni***@hotmail.com> wrote in message
> news:1164275826.495190.9500@j72g2000cwa.googlegroups.com...
>> In the past I always used "" everywhere for empty string in my code
>> without a problem.
>>
>> Now, do you think I should use String.Empty instead of "" (at all
>> times) ?
>>
>> Let me know your thoughts.
>>
>
>
Author
28 Nov 2006 9:42 PM
Dave Sexton
Hi Gabriel,

I don't think I'd be too concerned if different team members used "" or
string.Empty.  I'd leave that up to personal preference.  It really isn't
that important, IMO.

--
Dave Sexton

Show quote
"Gabriel Lozano-Morán" <ab***@frontbridge.com> wrote in message
news:unF1JQzEHHA.3436@TK2MSFTNGP03.phx.gbl...
>I personally prefer string.Empty over "" in code. It is just a matter of
>flavor but it can be a good thing to make it a guideline whether or not you
>to use "" vs string.Empty for the team.
>
> Gabriel Lozano-Morán
>
> "Dave Sexton" <dave@jwa[remove.this]online.com> wrote in message
> news:ex1125yEHHA.3820@TK2MSFTNGP02.phx.gbl...
>> Hi,
>>
>> I use string.Empty because that's what everyone I talked to had told me
>> since the original framework beta.
>>
>> Personally, I don't really care either way now, but it's just a habit.
>>
>> If I could shake the OCD involved I might be able to start using ""
>> instead, which seems cleaner to me ;)
>>
>> --
>> Dave Sexton
>>
>> <anoni***@hotmail.com> wrote in message
>> news:1164275826.495190.9500@j72g2000cwa.googlegroups.com...
>>> In the past I always used "" everywhere for empty string in my code
>>> without a problem.
>>>
>>> Now, do you think I should use String.Empty instead of "" (at all
>>> times) ?
>>>
>>> Let me know your thoughts.
>>>
>>
>>
>
>
Author
29 Nov 2006 3:42 AM
Gabriel Lozano-Morán
Like I said, whatever gets you off. It is like starting with a the letter
"p" for all your method arguments. Some do it and some don't.

Gabriel

Show quote
"Dave Sexton" <dave@jwa[remove.this]online.com> wrote in message
news:uAjOxYzEHHA.2104@TK2MSFTNGP03.phx.gbl...
> Hi Gabriel,
>
> I don't think I'd be too concerned if different team members used "" or
> string.Empty.  I'd leave that up to personal preference.  It really isn't
> that important, IMO.
>
> --
> Dave Sexton
>
> "Gabriel Lozano-Morán" <ab***@frontbridge.com> wrote in message
> news:unF1JQzEHHA.3436@TK2MSFTNGP03.phx.gbl...
>>I personally prefer string.Empty over "" in code. It is just a matter of
>>flavor but it can be a good thing to make it a guideline whether or not
>>you to use "" vs string.Empty for the team.
>>
>> Gabriel Lozano-Morán
>>
>> "Dave Sexton" <dave@jwa[remove.this]online.com> wrote in message
>> news:ex1125yEHHA.3820@TK2MSFTNGP02.phx.gbl...
>>> Hi,
>>>
>>> I use string.Empty because that's what everyone I talked to had told me
>>> since the original framework beta.
>>>
>>> Personally, I don't really care either way now, but it's just a habit.
>>>
>>> If I could shake the OCD involved I might be able to start using ""
>>> instead, which seems cleaner to me ;)
>>>
>>> --
>>> Dave Sexton
>>>
>>> <anoni***@hotmail.com> wrote in message
>>> news:1164275826.495190.9500@j72g2000cwa.googlegroups.com...
>>>> In the past I always used "" everywhere for empty string in my code
>>>> without a problem.
>>>>
>>>> Now, do you think I should use String.Empty instead of "" (at all
>>>> times) ?
>>>>
>>>> Let me know your thoughts.
>>>>
>>>
>>>
>>
>>
>
>

AddThis Social Bookmark Button