Witam, mamy taki kod:
public class Osoba
{
public string Imie { get; set; }
public Osoba()
{
}
protected Osoba(string imie)
{
this.Imie = imie;
}
public void create(string imie)
=> new Osoba(imie);
}
class Program
{
static void Main(string[] args)
{
Osoba a = new Osoba();
a.create("andrzej");
Console.WriteLine(a.Imie);
Console.ReadLine();
}
}
Problem jest taki, że na samym końcu normalnie wchodzi i ustawia this.Imie = Imie; które zawiera "andrzej", lecz nie potrafi go wyświetlić.
Sprawdziłem breakpointami i kolejność wygląda tak:
- Osoba a = new Osoba();
- public Osoba()
- a.create("andrzej");
- public void create(string imie) => new Osoba(imie);
- protected Osoba(string imie)
- this.Imie = imie; (w imie nadal znajduje się "andrzej")
- Console.WriteLine(a.Imie); /// a.Imie = null;