1 min read

Create interfaces in C# Part 3 – Compare cars

Now it’s time to compare the cars!

In the main method write code to instatiate 3 cars, two which are the same and then compare!

            var car1 = new Car()
            {
                Make = "Volvo",
                Model = "V60",
                Year = "2017"
            };

            var car2 = new Car()
            {
                Make = "Volvo",
                Model = "V60",
                Year = "2017"
            };

            var car3 = new Car()
            {
                Make = "Volvo",
                Model = "V60",
                Year = "2018"
            };

            Console.WriteLine($"Is car1 equal car 2? {car1.Equals(car2)}");
            Console.WriteLine($"Is car2 equal car 1? {car2.Equals(car1)}"); 
            Console.WriteLine($"Is car2 equal car 3? {car2.Equals(car3)}");

Now run the app and see if they are alike!

There we go!

Leave a Reply