public override string ToString() { StringBuilder builder = new StringBuilder(); builder.AppendLine(this.name); builder.AppendLine("Company:"); if (company != null) { builder.AppendLine(company.ToString()); } builder.AppendLine("Car:"); if (car != null) { builder.AppendLine(car.ToString()); } builder.AppendLine("Pokemon:"); foreach (var pokemon in pokemons) { builder.AppendLine(pokemon.ToString()); } builder.AppendLine("Parents:"); foreach (var parent in parents) { builder.AppendLine($"{parent.name} {parent.birthday}"); } builder.AppendLine("Children:"); foreach (var child in children) { builder.AppendLine($"{child.name} {child.birthday}"); } return(builder.ToString()); }
public override string ToString() { string output = $"{Name}\n"; output += $"Company:\n"; if (Company?.ToString() != null) { output += $"{Company?.ToString()}\n"; } output += $"Car:\n"; if (Car?.ToString() != null) { output += $"{Car?.ToString()}\n"; } output += $"Pokemon:\n"; Pokemons.ForEach(p => output += p.ToString() + "\n"); output += $"Parents:\n"; Parents.ForEach(p => output += p.ToString() + "\n"); output += $"Children:\n"; Children.ForEach(c => output += c.ToString() + "\n"); return(output.Trim()); }
public override string ToString() { string output = string.Empty; output = string.Concat(output, Name); output = string.Concat(output, Environment.NewLine); output = string.Concat(output, "Company:"); output = string.Concat(output, Environment.NewLine); if (Company != null) { output = string.Concat(output, Company.ToString()); output = string.Concat(output, Environment.NewLine); } output = string.Concat(output, "Car:"); output = string.Concat(output, Environment.NewLine); if (Car != null) { output = string.Concat(output, Car.ToString()); output = string.Concat(output, Environment.NewLine); } output = string.Concat(output, "Pokemon:"); output = string.Concat(output, Environment.NewLine); if (Pokemons.Any()) { foreach (var pokemon in Pokemons) { output = string.Concat(output, pokemon.ToString()); output = string.Concat(output, Environment.NewLine); } } output = string.Concat(output, "Parents:"); output = string.Concat(output, Environment.NewLine); if (Parents.Any()) { foreach (var parent in Parents) { output = string.Concat(output, parent.ToString()); output = string.Concat(output, Environment.NewLine); } } output = string.Concat(output, "Children:"); output = string.Concat(output, Environment.NewLine); if (Children.Any()) { foreach (var child in Children) { output = string.Concat(output, child.ToString()); output = string.Concat(output, Environment.NewLine); } } return(output); }