Click here to Skip to main content
15,897,518 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
C#
class A
{
    public int Item()
    {
        throw new NotImplementedException();
    }

    public int this[int x] // error CS0102: The type 'A' already contains a definition for 'Item'
    {
        get { throw new NotImplementedException(); }
    }
}

Thanks for your help....

regrads
Nikhil
Posted
Updated 8-Jun-20 4:55am
v3
Comments
benjamine 1-Jun-10 9:38am    
The answer is here:
http://social.msdn.microsoft.com/forums/en-US/csharplanguage/thread/dbd2b263-824c-4f5b-ba18-2f6d117c8ad1/

C# creates an "Item" property automatically for indexers, but you can override it's name using an Attribute:

[System.Runtime.CompilerServices.IndexerName("MyItems"]
public Item this[int row, int col] { ... }
imendan 18-Jul-11 1:05am    
Thanks a lot!

Yes, that's true.
Both your members are called Item.
There is a method called Item and an indexer... (all indexers are automatically called Item)
Just have a look at the documentation for class List for example. There look at the members. You should see Item. Click on it and you will be viewing the documentation about the indexer!
 
Share this answer
 
"this" is a keyword - you cannot name any method, field or property "this".
Change the name, and all will be well.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900