Item and indexers

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Be aware that if you create a class named 'Item', you can't create an indexer

public class Item {
protected ArrayList _list = new ArrayList();
public string this[int index] {
return (string)_list[index];
}
}

It took me long time to figure this one out. It seems like the compiler
creates a method named 'Item' for indexers (under the hood) and the compiler
won't allow you the have a method or property with the same name as the class.

MS should change the error code for this one, making it easier to spot
 
Frode said:
Be aware that if you create a class named 'Item', you can't create an
indexer [...] It took me long time to figure this one out. [...]
MS should change the error code for this one, making it easier to spot

Thanks for your feedback, Frode. I agree with your assessment, and although
I can't guarantee that this behaviour will change in the final version of
VS2005, I have notified the appropriate people. If you encounter any more
issues in the future, I strongly encourage you to send beta feedback to
Microsoft through the MSDN Product Feedback Center:

http://lab.msdn.microsoft.com/productfeedback/
 
Back
Top