4

This is my Interface:

interface IComandos<T>
{
    void Inserir();
    IList<T> Pesquisar(string termo);
    void Editar();
    void Excluir();
}

Here, a class implementing the Interface:

 class Partido : IComandos<Partido>
        {
            public string Nome { get; set; }
            public string Sigla { get; set; }
        ...

    public IList<Partido> Pesquisar(string termo)
        {
            throw new NotImplementedException();
        }

Question: I need my "Pesquisar" method to be static. How can I do it? I really need my Method to work like this -> Partido.Pesquisar("something");

  • 1
    _"I need my "Pesquisar" method to be static"_ Why (do you think that) ? – H H Jun 30 '17 at 23:09
  • Well if you really need a static method, define a static method. What is the problem? *Partido* is a class and you can define static methods for a class – Sir Rufo Jun 30 '17 at 23:16

1 Answers1

-1

From MSDN Interfaces (C# Programming Guide):

An interface cannot contain constants, fields, operators, instance constructors, destructors, or types. It cannot contain static members. Interfaces members are automatically public, and they cannot include any access modifiers.

So the answer is: no, you cannot define static member in interface.

Sergey Berezovskiy
  • 232,247
  • 41
  • 429
  • 459