如何修复问题界面C#(控制台.NET Core):CS0535和CS1061

时间:2020-01-25 21:07:20

标签: c# .net-core interface

我是新手,对接口有问题,我用谷歌搜索,但没有找到,我认为此错误是由于我使用(Console .NET Core)引起的。

[编辑]::我修复了“ SavaData”,但我认为接口在.Net Core中不起作用。

错误是:

CS0535“基本”和“客户”未实现接口成员“ IPeople.SaveData()”

CS0535 C#“客户”未实现接口成员

CS1061 C#“客户”不包含的定义且无法访问 扩展方法,接受“ Customer”类型的第一个参数 被找到(您是否缺少using指令或程序集引用?)

那个问题:

我的界面

using Customer1;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.IO;
using System.Text;

namespace Interface
{
    public interface IPeople 
    {
        public void SavaData();
    }
}

我的继承人:

using Interface;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.IO;
using System.Text;

namespace Base1
{
    public class Base : IPeople
    {
        public string Name;
        public string NPhone; 
        public string CPF;


        public Base(string nome, string Nphone, string CPF)
        {
            //This can't equal a null or blanc
            this.Name = nome;
            this.NPhone = Nphone;
            this.CPF = CPF;
        }
        public Base() { }

        private string DirectoryMaster()
        {
            return ConfigurationManager.AppSettings["Directory1"] + this.GetType().Name + ".txt";
        }
        public void SaveData() 
        {

            var SPeople = this.ReadPeople(); 
            SPeople.Add(this);
            if (File.Exists(DirectoryMaster()))
            {
                StreamWriter r = new StreamWriter(DirectoryMaster());
                string Data = "nome;telefone;CPF;"; //n";
                r.WriteLine(Data);
                foreach (Base c in SPeople)
                {
                    var linha = c.Name + ";" + c.NPhone + ";" + c.CPF + ";";
                    r.WriteLine(linha);
                }

                r.Close();
            }
        }

        public virtual List<Base> ReadPeople()
        {
            var dados = new List<Base>();

            if (File.Exists(DirectoryMaster()))
            {
                //Console.WriteLine("Your file content is:");
                using (StreamReader arquivo = File.OpenText(DirectoryMaster()))
                {
                    string linha;
                    int i = 0;
                    while ((linha = arquivo.ReadLine()) != null)
                    {
                        i++;
                        if (i == 1) continue;
                        var DataCustomer = linha.Split(';');


                        var b = new Base { Name = DataCustomer[0], NPhone = DataCustomer[1], CPF = DataCustomer[2] };


                        dados.Add(b);

                    }
                }

            }

            return dados;
        }

    }
}

我的客户。cs

using System.Configuration; 
using System.IO;
using System.Text;
using User1;



namespace Customer1
{
    public class Customer : IPeople
    {
        public string Name; 
        public string NPhone;
        public string CPF;


        public Customer(string nome, string Nphone, string CPF)
        {

            this.Name = nome;
            this.NPhone = Nphone;
            this.CPF = CPF;
        }
        public Customer()
        {

        }
}

tz,请帮我,谢谢

2 个答案:

答案 0 :(得分:2)

您看到的问题之一与界面中的错字有关。

public void SavaData();

上述代码应改为:

void SaveData();

答案 1 :(得分:0)

因此,您遇到的第一个错误是说您正在实现Customer类中的接口,但没有实现来自该接口的方法。这就是为什么发生此问题的原因。

还有另一件事,即接口,不需要公众对其方法的定义。

第二个错误,可能是您试图在某个类的构造函数上传递客户,但是您没有在该类上添加“使用客户”。因此.NET无法找到所需的类。

请尝试为我们放置Customer类,因为这样会更容易发现这是否真的是错误。