Re: Strings.. Objects or not???
From: Jon Skeet [C# MVP] (skeet_at_pobox.com)
Date: 07/09/04
- Next message: Grigs: "RE: Check If User Exists..."
- Previous message: Jon Skeet [C# MVP]: "Re: Strings.. Objects or not???"
- In reply to: Rigga: "Re: Strings.. Objects or not???"
- Next in thread: Patrick Steele [MVP]: "Re: Strings.. Objects or not???"
- Messages sorted by: [ date ] [ thread ]
Date: Fri, 9 Jul 2004 14:44:05 +0100
Rigga <s@v.c> wrote:
> Thanks all for your replies but I'm still confused.
>
> So coding "veg" anywhere will only ever create one object?
>
> and assigning that object to the reference variable as
>
> x1 as string = "veg"
>
> points to the same object as
>
> x2 as string = "veg"
>
> "veg" being the object?
>
> actually, it has always been kind of strange hat you do not have to code
>
> x1 as New String to instantiate the object.
>
> So we are saying that string does not behave in the same way as other
> objects?
>
> Anyway, now that I know this I'll have to code around it.. thanks all..
String behaves like other objects for the most part, but string
literals are interned automatically, so that within a single AppDomain,
all references to the same string literal are references to the same
actual string.
One *really* weird bit about string is that if you create a new string
using the char[] constructor, but give it an empty array, it doesn't
actually create a new string at all - it just returns String.Empty.
Very odd indeed.
-- Jon Skeet - <skeet@pobox.com> http://www.pobox.com/~skeet If replying to the group, please do not mail me too
- Next message: Grigs: "RE: Check If User Exists..."
- Previous message: Jon Skeet [C# MVP]: "Re: Strings.. Objects or not???"
- In reply to: Rigga: "Re: Strings.. Objects or not???"
- Next in thread: Patrick Steele [MVP]: "Re: Strings.. Objects or not???"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|