CS0029 Não é possível converter implicitamente tipo "System.Collections.Generic.List<Classes.Base>" em "System.Collections.Generic.List<Classes.IPessoa>"

Gabriel Teodoro 21 Reputation points
2023-01-02T14:13:17.057+00:00

Estava tentando retornar dados de clientes de um arquivo txt estava tudo funcionando ai me vem esse erro

aqui o codigo fonte

public List<IPessoa> Ler()  
        {  
            var dados = new List<Base>();  
            if (File.Exists(DiretorioComArquivo()))  
            {  
                using (StreamReader arquivo = File.OpenText(DiretorioComArquivo()))  
                {  
                    string? linha;  
                    int i = 0;  
                    while ((linha = arquivo.ReadLine()) != null)  
                    {  
                        i++;  
                        if (i == 1) { continue; }  
                        var BaseArquivo = linha.Split(';');  
                        var b  = (IPessoa)Activator.CreateInstance(this.GetType());  
  
                        if (b != null)  
                        {  
                            b.SetNome(BaseArquivo[0]);  
                            b.SetTelefone(BaseArquivo[1]);  
                            b.SetCPF(BaseArquivo[2]);  
                            dados.Add((Base)b);  
  
                        }  
                         
                    }  
                }  
                return dados;  
Not Monitored
Not Monitored
Tag not monitored by Microsoft.
35,529 questions
0 comments No comments
{count} votes

Accepted answer
  1. Dave Patrick 425.8K Reputation points MVP
    2023-01-02T14:18:08.61+00:00

    Q&A forums are currently English only. I'd try asking for help over here in dedicated forums.
    https://social.msdn.microsoft.com/Forums/pt-br/home
    https://social.technet.microsoft.com/Forums/pt-br/home
    https://answers.microsoft.com/pt-br

    --please don't forget to upvote and Accept as answer if the reply is helpful--


0 additional answers

Sort by: Most helpful