Archived

This topic is now archived and is closed to further replies.

C# Properties Problem

This topic is 5679 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

The code speaks for itself...
  
    ListNode ln1 = new ListNode("1");
    ListNode ln2 = new ListNode("2");
    ln1.Next = ln2;
    Console.WriteLine(ln1.Content);
    Console.WriteLine(ln2.Content);
    Console.WriteLine(ln1.Next.Content);  // Dies here.

  
Content is a string property of ListNode, Next is a ListNode property of ListNode (next node in the list). Any ideas? [edited by - Xolution on June 30, 2002 7:43:28 PM]

Share this post


Link to post
Share on other sites
What the code for the Next property look like? What about other (relevant) bits of ListNode? I assume you wrote ListNode yourself...


codeka.com - Just click it.

Share this post


Link to post
Share on other sites
Ah, no worries now.
I had my set part like

set {
this._next = Next;
}

Changed it to value, now it all seems to work...

Share this post


Link to post
Share on other sites
I think Eric Gunnerson mentioned something about making that a compiler error - at least this variant:

  
public SomeType SomeThing
{
get{ return SomeThing; } //instead of someThing - the private instance variable

}

Share this post


Link to post
Share on other sites