druknhik Posted August 17, 2004 Posted August 17, 2004 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#? Quote
Administrators PlausiblyDamp Posted August 17, 2004 Administrators Posted August 17, 2004 Could you post your code for how you have defined the indexer and the class it returns? Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
druknhik Posted August 17, 2004 Author Posted August 17, 2004 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. Quote
Administrators PlausiblyDamp Posted August 17, 2004 Administrators Posted August 17, 2004 What version of the framework / VS are you using? Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
druknhik Posted August 17, 2004 Author Posted August 17, 2004 What version of the framework / VS are you using? I'm using VS 2005, I think it's the framework is ver 2.0 Quote
Administrators PlausiblyDamp Posted August 17, 2004 Administrators Posted August 17, 2004 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? Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
druknhik Posted August 17, 2004 Author Posted August 17, 2004 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. Quote
Administrators PlausiblyDamp Posted August 17, 2004 Administrators Posted August 17, 2004 Tried it here with a simple class and it worked aas expected, feel free to post / attach your code and I'll have a look. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.