[Solved] C# parameters in interface [closed]


Interfaces are used as a contract for classes that inherit it. This means any public methods/properties you want the interface to expose, must also be exposed in the inherited class.

In the case above, you don’t have any public methods/properties exposed in the interface. Let me show you an example.

Interface ITest
{
   void AddPerson(string name, string age);
}

Interface IPerson
{
    string ReturnPersonsAge(string name);
}

/// This must expose the AddPerson method
/// This must also expose the ReturnPersonByAge method
class Example : ITest, IPerson
{
   Dictionary<string, string> people = new Dictionary<string, string>();

   void AddPerson(string name, string age)
   {
      people.Add(name, age);
   }

   string ReturnPersonsAge(string name)
   {
      return people[name];
   }
}

I hope that helps, but feel free to ask more questions so I can help narrow down your question.

4

solved C# parameters in interface [closed]