-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
40 lines (35 loc) · 1.11 KB
/
Program.cs
File metadata and controls
40 lines (35 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
using System;
namespace Interfaces
{
// Ref: https://docs.microsoft.com/en-us/dotnet/csharp/fundamentals/types/interfaces
class Program
{
interface IEquatable
{
bool Equals(object obj);
}
public class Car : IEquatable
{
public string Make { get; set; }
public string Model { get; set; }
public string Year { get; set; }
// Implementation of IEquatable<T> interface
public override bool Equals(object obj)
{
if (!(obj is Car))
{
return false;
}
Car car = (Car)obj;
return (this.Make, this.Model, this.Year) ==
(car.Make, car.Model, car.Year);
}
}
static void Main(string[] args)
{
Car carA = new Car { Make = "test_make", Model = "test_model", Year = "2021" };
Car carB = new Car { Make = "test_make", Model = "test_model", Year = "2021" };
Console.WriteLine(carA.Equals(carB));
}
}
}