示例#1
0
        static void Main(string[] args)
        {
            // Put code here to create 3 car instances

            var car = new AnotherCar("Ford", "Mondeo")
            {
                Cost = 10
            };
            var car1 = new AnotherCar("Tesla", "I don't know cars")
            {
                Cost = 10000000
            };
            var car2 = new AnotherCar("Toyota", "Prius")
            {
                Cost = 5000
            };
            // Add a method named 'Display'to the AnotherCar Class
            // This method should output the details of a  car instance
            // to the Console

            // Put code here to call that method to display the
            // details of a each car instance

            var anotherCar = new AnotherCar();

            anotherCar.Display(car);
            anotherCar.Display(car1);
            anotherCar.Display(car2);
        }
        static void Main(string[] args)
        {
            AnotherCar car1 = new AnotherCar("Vauxhall");// contructor method with one argument passed
            car1.Colour = "Blue";
            car1.Type = "Astra";
            car1.Cost = 20000;

            AnotherCar car2 = new AnotherCar("Vauxhall");// contructor method with one argument passed
            car2.Colour = "Blue";
            car2.Type = "Astra";
            car2.Cost = 20000;

            AnotherCar car3 = new AnotherCar("Vauxhall");// contructor method with one argument passed
            car3.Colour = "Blue";
            car3.Type = "Astra";
            car3.Cost = 20000;

            Console.WriteLine(AnotherCar.display(car3));

            Console.ReadKey();

            // Put code here to create 3 car instances

            // Add a method named 'Display'to the AnotherCar Class
            // This method should output the details of a  car instance
            // to the Console

            // Put code here to call that method to display the
            // details of a each car instance
        }
示例#3
0
 public void Display(AnotherCar car)
 {
     Console.WriteLine(
         $"The car is a" +
         " " + car.Country +
         " " + car.Make +
         " " + car.Type +
         " " + car.Colour +
         " " + car.Cost
         );
     Console.ReadLine();
 }
        public static string display(AnotherCar car)
        {
            string objectAsXmlString;

                System.Xml.Serialization.XmlSerializer xs = new System.Xml.Serialization.XmlSerializer(car.GetType());
                using (System.IO.StringWriter sw = new System.IO.StringWriter())
                {
                    try
                    {
                        xs.Serialize(sw, car);
                        objectAsXmlString = sw.ToString();
                    }
                    catch (Exception ex)
                    {
                        objectAsXmlString = ex.ToString();
                    }
                }

                return objectAsXmlString;
        }