Exemple #1
0
        public override string ToString()
        {
            string model  = $"{Model}:";
            string engine = Engine.ToString();
            string weight;
            string color;

            if (Weight != 0)
            {
                weight = $"  Weight: {Weight}";
            }
            else
            {
                weight = $"  Weight: n/a";
            }

            if (Color != null)
            {
                color = $"  Color: {Color}";
            }
            else
            {
                color = $"  Color: n/a";
            }

            return($"{model}\n{engine}\n{weight}\n{color}");
        }
        public override string ToString()
        {
            var sb = new StringBuilder();

            sb.Append($"{CarModel}:");
            sb.AppendLine();
            sb.Append($"  {Engine.ToString()}");
            sb.AppendLine();
            sb.Append(Weight == 0 ? "  Weight: n/a" : $"  Weight: {Weight}");
            sb.AppendLine();
            sb.Append(String.IsNullOrEmpty(Color) ? "  Color: n/a" : $"  Color: {Color}");

            return(sb.ToString().TrimEnd());
        }