Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I would like to do something like this:

 

Class.Property = something;

 

[] is the indexer for some List<> in Class.

 

This won't work, because this doesn't seem to return a reference to the object whose property I would like to modify.

 

In C++, would have been able to do something like this easily by overloading the [] operator, and making it return a reference.

 

How could I do the same in C#?

Posted
Could you post your code for how you have defined the indexer and the class it returns?

 

public Class this[int index]

{

get

{

return Elements[index];

}

set

{

Elements[index] = value;

}

}

 

Elements is a List<Class>

 

Did you ask me to show how Class is defined? If so, there has to something you would like to see...I won't put the whole thing, it's rather large.

Posted
public Class this[int index] should return an instance of Class - you should have access to all the properties and methods of Class. What properties / methods is it displaying instead?

 

In the watch, it displays everything like it should.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...