Click here to Skip to main content
16,018,460 members
Home / Discussions / C#
   

C#

 
GeneralRe: Should I use new for a string? Pin
Hamed Musavi11-Jun-08 6:31
Hamed Musavi11-Jun-08 6:31 
GeneralRe: Should I use new for a string? Pin
User 665811-Jun-08 6:57
User 665811-Jun-08 6:57 
GeneralRe: Should I use new for a string? Pin
S. Senthil Kumar11-Jun-08 8:19
S. Senthil Kumar11-Jun-08 8:19 
AnswerRe: Should I use new for a string? Pin
Guffa11-Jun-08 7:23
Guffa11-Jun-08 7:23 
GeneralRe: Should I use new for a string? Pin
Hamed Musavi11-Jun-08 7:29
Hamed Musavi11-Jun-08 7:29 
GeneralRe: Should I use new for a string? Pin
Guffa11-Jun-08 7:40
Guffa11-Jun-08 7:40 
GeneralRe: Should I use new for a string? Pin
BadKarma11-Jun-08 10:26
BadKarma11-Jun-08 10:26 
GeneralRe: Should I use new for a string? Pin
Guffa11-Jun-08 13:13
Guffa11-Jun-08 13:13 
BadKarma wrote:
This is not entirely true. string is a special class. It is indeed a reference type but it behaves like a value type.


There is nothing special about the string class. It may seem like it behaves like a value type, but actually it doesn't.

BadKarma wrote:
If it was a reference type like any other the following should return true but it doesn't.


It's a reference type just like any other, and just as with any other reference type, replacing a reference to an object neither changes the content of the object nor any other reference to the object.

This is what the code is doing:

1. Declare a string reference called "s1".
2. Get the reference to the "hello" literal string.
3. Store the reference in the "s1" variable.

- The s1 variable now contains a reference to "hello".

4. Declare a string reference called "s2".
5. Get the reference from the "s1" variable.
6. Store the reference in the "s2" variable.

- The s2 variable now contains a reference to "hello".

7. Get the reference to the "world" literal string.
8. Store the reference in the "s1" variable.

- The s1 varaible now contains a reference to "world".

9. Compare the contents of the strings that s1 and s2 reference.

- As s1 references "world" and s2 references "hello", the comparison returns false.

Despite everything, the person most likely to be fooling you next is yourself.

AnswerRe: Should I use new for a string? Pin
Christian Graus11-Jun-08 6:24
protectorChristian Graus11-Jun-08 6:24 
GeneralRe: Should I use new for a string? Pin
Hamed Musavi11-Jun-08 6:29
Hamed Musavi11-Jun-08 6:29 
GeneralRe: Should I use new for a string? [modified] Pin
S. Senthil Kumar11-Jun-08 6:46
S. Senthil Kumar11-Jun-08 6:46 
GeneralRe: Should I use new for a string? Pin
Hamed Musavi11-Jun-08 7:14
Hamed Musavi11-Jun-08 7:14 
AnswerRe: Should I use new for a string? Pin
Guffa11-Jun-08 7:27
Guffa11-Jun-08 7:27 
GeneralRe: Should I use new for a string? Pin
Hamed Musavi11-Jun-08 7:30
Hamed Musavi11-Jun-08 7:30 
GeneralRe: Should I use new for a string? Pin
Christian Graus11-Jun-08 6:49
protectorChristian Graus11-Jun-08 6:49 
GeneralRe: Should I use new for a string? Pin
PIEBALDconsult11-Jun-08 15:35
mvePIEBALDconsult11-Jun-08 15:35 
QuestionInstaller Issues Pin
Russell Jones11-Jun-08 5:43
Russell Jones11-Jun-08 5:43 
AnswerRe: Installer Issues Pin
Christian Graus11-Jun-08 5:54
protectorChristian Graus11-Jun-08 5:54 
GeneralRe: Installer Issues Pin
Russell Jones11-Jun-08 6:02
Russell Jones11-Jun-08 6:02 
AnswerRe: Installer Issues Pin
leppie11-Jun-08 5:57
leppie11-Jun-08 5:57 
GeneralRe: Installer Issues Pin
Russell Jones11-Jun-08 6:01
Russell Jones11-Jun-08 6:01 
GeneralRe: Installer Issues Pin
leppie11-Jun-08 6:04
leppie11-Jun-08 6:04 
GeneralRe: Installer Issues Pin
Russell Jones11-Jun-08 6:26
Russell Jones11-Jun-08 6:26 
GeneralRe: Installer Issues Pin
leppie11-Jun-08 6:57
leppie11-Jun-08 6:57 
GeneralRe: Installer Issues Pin
leppie11-Jun-08 6:05
leppie11-Jun-08 6:05 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.