Click here to Skip to main content
15,903,012 members
Home / Discussions / C#
   

C#

 
AnswerRe: Sync confusion Pin
Luc Pattyn13-Mar-09 2:56
sitebuilderLuc Pattyn13-Mar-09 2:56 
QuestionFrame CheckSum Calculation Problem Pin
ajorge200813-Mar-09 0:01
ajorge200813-Mar-09 0:01 
AnswerRe: Frame CheckSum Calculation Problem [modified] Pin
DaveyM6913-Mar-09 0:14
professionalDaveyM6913-Mar-09 0:14 
QuestionRegular expressions in C# Pin
KeithF12-Mar-09 23:28
KeithF12-Mar-09 23:28 
AnswerRe: Regular expressions in C# Pin
whaka12-Mar-09 23:48
whaka12-Mar-09 23:48 
AnswerRe: Regular expressions in C# Pin
psi_u13-Mar-09 1:05
psi_u13-Mar-09 1:05 
AnswerRe: Regular expressions in C# Pin
#realJSOP13-Mar-09 2:26
professional#realJSOP13-Mar-09 2:26 
Questionstring reference type? Pin
__DukeNukem__12-Mar-09 23:25
__DukeNukem__12-Mar-09 23:25 
Hi you all,

I am currently teaching myself C# and .Net. This works fine so long but now I have a question:

I experimented a bit with the hash codes of objects and when I ran my example app I had to notice that string does not behave like I expected. But first the example:
string s1 = "teststring";
string s2 = s1;
Console.WriteLine(s1 + " " + s1.GetHashCode());
Console.WriteLine(s2 + " " + s2.GetHashCode());

s2 = "changed";
Console.WriteLine(s1 + " " + s1.GetHashCode());
Console.WriteLine(s2 + " " + s2.GetHashCode());


The result I expected was that s2 will point to the same string object as s1. Therefore changing s2 would result in changing the same object that both string references point to, i.e. that both strings have the same values. But the output of the code is the following:

teststring -1549391391
teststring -1549391391
teststring -1549391391
changed 114681301

So I just have a simple question: Why?

Would be happy to get some help on this.

Thank you in advance!
AnswerRe: string reference type? Pin
DaveyM6912-Mar-09 23:37
professionalDaveyM6912-Mar-09 23:37 
GeneralRe: string reference type? Pin
__DukeNukem__12-Mar-09 23:45
__DukeNukem__12-Mar-09 23:45 
GeneralRe: string reference type? Pin
DaveyM6912-Mar-09 23:59
professionalDaveyM6912-Mar-09 23:59 
GeneralRe: string reference type? Pin
Luc Pattyn13-Mar-09 3:10
sitebuilderLuc Pattyn13-Mar-09 3:10 
GeneralRe: string reference type? Pin
DaveyM6913-Mar-09 4:25
professionalDaveyM6913-Mar-09 4:25 
Questionvehicle tracking Pin
R.Krishnakumar12-Mar-09 23:14
R.Krishnakumar12-Mar-09 23:14 
AnswerRe: vehicle tracking Pin
Eddy Vluggen12-Mar-09 23:23
professionalEddy Vluggen12-Mar-09 23:23 
GeneralRe: vehicle tracking Pin
R.Krishnakumar12-Mar-09 23:39
R.Krishnakumar12-Mar-09 23:39 
GeneralRe: vehicle tracking Pin
Pete O'Hanlon12-Mar-09 23:49
mvePete O'Hanlon12-Mar-09 23:49 
GeneralRe: vehicle tracking Pin
stancrm13-Mar-09 0:05
stancrm13-Mar-09 0:05 
GeneralRe: vehicle tracking Pin
Eddy Vluggen13-Mar-09 1:33
professionalEddy Vluggen13-Mar-09 1:33 
AnswerRe: vehicle tracking Pin
Michael Bookatz13-Mar-09 0:30
Michael Bookatz13-Mar-09 0:30 
AnswerRe: vehicle tracking Pin
#realJSOP13-Mar-09 2:28
professional#realJSOP13-Mar-09 2:28 
QuestionRunning process under another user account Pin
Paddy Boyd12-Mar-09 23:12
Paddy Boyd12-Mar-09 23:12 
QuestionNeed Help in Developing Basic biometric software using C# and VERILOOK SDK 3.2 for a diploma level student Pin
RogerLum12-Mar-09 21:40
RogerLum12-Mar-09 21:40 
AnswerRe: Need Help in Developing Basic biometric software using C# and VERILOOK SDK 3.2 for a diploma level student Pin
0x3c012-Mar-09 21:45
0x3c012-Mar-09 21:45 
AnswerRe: Need Help in Developing Basic biometric software using C# and VERILOOK SDK 3.2 for a diploma level student Pin
Pete O'Hanlon12-Mar-09 23:38
mvePete O'Hanlon12-Mar-09 23:38 

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.