Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Linked List Problem in C#
Index -> General Programming
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
person




PostPosted: Sat Nov 22, 2008 7:38 pm   Post subject: Linked List Problem in C#

In this problem, foo and bar are both single linked lists. Next is a member of the list which points to the next element in the list.

code:

foo = bar;                             
Console.WriteLine (bar.Next==null);
foo.Next = null;
Console.WriteLine (bar.Next==null);


When I run this portion of the code in my program, the output is:

False
True

Why is this?
Sponsor
Sponsor
Sponsor
sponsor
person




PostPosted: Sat Nov 22, 2008 8:58 pm   Post subject: Re: Linked List Problem in C#

Btw, the linked lists are instances of a class called List which contains a variable to hold a value and a variable to hold a variable of type List which points to another value and List. So I don't think this is an issue of pointers since I don't believe they are pointing to the same location in memory.
OneOffDriveByPoster




PostPosted: Sat Nov 22, 2008 10:53 pm   Post subject: Re: Linked List Problem in C#

person @ Sat Nov 22, 2008 7:38 pm wrote:
code:

foo = bar;
Why do you believe that foo would be different from bar after that?
rdrake




PostPosted: Sat Nov 22, 2008 11:52 pm   Post subject: RE:Linked List Problem in C#

Foo is not a clone of bar, it's just a reference to it. Try making the line say something like foo = bar.Clone() and see what happens.
Display posts from previous:   
   Index -> General Programming
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 4 Posts ]
Jump to:   


Style:  
Search: