Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace ExperimentProject
- {
- public class Program
- {
- public abstract class MyId
- {
- public abstract int Value { get; set; }
- public static bool operator ==(MyId a, MyId b)
- {
- if (a.GetType() != b.GetType())
- return false;
- if (a.Value == b.Value)
- return true;
- return false;
- }
- public static bool operator !=(MyId a, MyId b)
- {
- return !(a == b);
- }
- }
- public class MyId1 : MyId
- {
- public MyId1(int id)
- {
- Value = id;
- }
- public override int Value { get; set; }
- }
- public class MyId2 : MyId
- {
- public MyId2(int id)
- {
- Value = id;
- }
- public override int Value { get; set; }
- }
- public static void Main()
- {
- var q1 = new MyId1(2);
- var q2 = new MyId1(2);
- var q3 = new MyId2(2);
- bool f1 = q1 == q2;
- bool f2 = q1 == q3;
- Console.WriteLine(f1); //true
- Console.WriteLine(f2); //false
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement