Send parameters to a C#interface

Asked

Viewed 459 times

2

I created a class called descricaoo that will receive some data parameters and will add in a List of an interface called IInstrucao. But give an error "the descricaoo class is not implemented to an interface" How to fix this error? There is another way to send this data directly to the interface IInstrucao?

class descricaoo:IInstrucao
{
   private string descricaobol;
   public descricaoo (int ibanco, int codigo, string descricaobol, int qtde)
   {
     this.descricaobol = descricaobol;
     List<IInstrucao> desci = new List<IInstrucao>();
     desci.Add(new descricaoo(ibanco,codigo,descricaobol,qtde));
   }  
 }

public interface IInstrucao
{
    IBanco Banco { get; set; }
    int Codigo { get; set; }
    string Descricao { get; set; }
    int QuantidadeDias { get; set; }
}
  • Your Description class is not implementing the Iinstrucao Interface properties

  • So your class doesn’t have the methods or the properties of the interface...

  • Take a look at [tour]. You can accept an answer if it solved your problem. You can vote on every post on the site as well. Did any help you more? You need something to be improved?

2 answers

4

You’re saying implement the interface, so do this:

using System.Collections.Generic;

public class Program {
    public static void Main() {}
}

class descricaoo : IInstrucao {
    private string descricaobol;
    public descricaoo (int ibanco, int codigo, string descricaobol, int qtde) {
        this.descricaobol = descricaobol;
        List<IInstrucao> desci = new List<IInstrucao> { new descricaoo(ibanco,codigo,descricaobol,qtde) };
    }
    public IBanco Banco { get; set; }
    public int Codigo { get; set; }
    public string Descricao { get; set; }
    public int QuantidadeDias { get; set; }
}

public interface IInstrucao {
    IBanco Banco { get; set; }
    int Codigo { get; set; }
    string Descricao { get; set; }
    int QuantidadeDias { get; set; }
}

public interface IBanco {}

Behold working in the ideone. And in the .NET Fiddle. Also put on the Github for future reference.

  • Thanks mustache!

2

You need to define all interface items in the class, as enunciates the architecture by C contracts#:

class descricaoo: IInstrucao
{
   private string descricaobol;
   public descricaoo (int ibanco, int codigo, string descricaobol, int qtde)
   {
     this.descricaobol = descricaobol;
     List<IInstrucao> desci = new List<IInstrucao>();
     desci.Add(new descricaoo(ibanco,codigo,descricaobol,qtde));
   }  

    public IBanco Banco { get; set; }
    public int Codigo { get; set; }
    public string Descricao { get; set; }
    public int QuantidadeDias { get; set; }
 }

public interface IInstrucao
{
    IBanco Banco { get; set; }
    int Codigo { get; set; }
    string Descricao { get; set; }
    int QuantidadeDias { get; set; }
}
  • 1

    ...had just generated the class, was going to post when I saw the new response alert. I can barely see your movements!

  • 1

    Thank you Gypsy!

Browser other questions tagged

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