Item and indexers

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
 
D

Derrick Coetzee [MSFT]

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/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top