Implement Dictionary as C#interface

Asked

Viewed 82 times

1

I am trying to set a Dictionary on my interface, but it is saying that the main class did not implement Dictionary.

Interface.Cs

public interface IItem
{
    event Action<string, string, string, string, string, string, string, string, string, string, string> ItemToDataGrid;
    void Search();
    int SearchType { get; set; }
    Dictionary<string, string> SearchKey();
}

Main.Cs

public class Item : IItem
{
    public int _SearchType;
    public int SearchType
    {
        get
        {
            return this._SearchType;
        }
        set
        {
            this._SearchType = value;
        }
    }

    Dictionary<string, string> searchKey = new Dictionary<string, string>()
    {
        { "Item", "" },            
        { "Character", "" },
    };

I’m doing something wrong?

  • Yes, where is the SearchKey(), the Search() and the ItemToDataGrid? Without implementing them will give error even.

  • I pasted only a small part of the code, the error is in the implementation of Dictionary.

1 answer

0

Your class Item has to this:

oublic class Item : IItem
{
    public int _SearchType;
    public int SearchType
    {
        get
        {
            return this._SearchType;
        }
        set
        {
            this._SearchType = value;
        }
    }
    Dictionary<string, string> searchKey = new Dictionary<string, string>()
{
{ "Item", "" },
{ "Character", "" },
};
    public event Action<string, string, string, string, string, string, string, string, string, string, string> ItemToDataGrid;

    public void Search()
    {
        //TODO: Seu código aqui
    }

    public Dictionary<string, string> SearchKey()
    {
        //TODO: Seu código aqui

        return searchKey;
    }
}
  • Is that I pasted only a small part of the code, vs is stating that the error is in implementing the datagrid.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.