-3
I have a class with two constructors. The empty constructor (no arguments) is not working.
Script shows no error. One of the constructors receives the parameters nome
and limitedecredito
; and another, empty, initializes the CPF
.
Turns out the countryside cpf
(TCPF) is getting the value NULL
.
Builder of the customer class:
public Cliente():base()
{
}
Main Program:
(...)
case 1:
Console.Clear();
c1 = new Cliente();
Console.Write("CPF:");
CPF = Console.ReadLine();
if (c1.setCPF(CPF) == false)
{
Console.WriteLine("CPF inválido");
Console.ReadKey();
break;
}
Console.Write("Nome:");
string nome = Console.ReadLine();
Console.Write("Limite de credito R$:");
double limitecredito = double.Parse(Console.ReadLine());
c1 = new Cliente(nome, limitecredito);
LC.Add(c1);
Console.Write("Cadastro realizado com sucesso");
Console.ReadKey();
break;
(...)
Class Cliente
:
private double limitecredito;
public Cliente():base()
{
}
public Cliente(string n, double limitec) : base(n)
{
limitecredito = limitec;
}
Class Pessoa
(Mother):
private string nome;
private TCPF cpf;
public Pessoa()
{
cpf = new TCPF();
}
public Pessoa(string n)
{
cpf = new TCPF();
nome = n;
}
public string Nome
{
get { return nome; }
}
public bool setCPF(string X)
{
return cpf.ValidaCpf(X);
}
public string Cpf
{
get { return cpf.Cpf; }
}
Where is the error?
– CypherPotato
https://dotnetfiddle.net/U84zk8 see this, and error reading ?
– Rovann Linhalis
The program is without any error happens that I created two constructs one to store the attributes name and limit credit and one to start the CPF happens that the CPF(object) is getting the value NULL
– Paulo Eduardo