using System.Reflection; MethodInfo method1 = typeof(MyClass).GetMethod("MyMethod"); MethodInfo method2 = typeof(MyClass).GetMethod("MyOtherMethod"); if (method1.Equals(method2)) { Console.WriteLine("The methods are equal."); } else { Console.WriteLine("The methods are not equal."); }
using System.Reflection; PropertyInfo prop1 = typeof(MyClass).GetProperty("MyProperty"); PropertyInfo prop2 = typeof(MyClass).GetProperty("MyOtherProperty"); if (prop1.Equals(prop2)) { Console.WriteLine("The properties are equal."); } else { Console.WriteLine("The properties are not equal."); }
using System.Reflection; FieldInfo field1 = typeof(MyClass).GetField("MyField"); FieldInfo field2 = typeof(MyClass).GetField("MyOtherField"); if (field1.Equals(field2)) { Console.WriteLine("The fields are equal."); } else { Console.WriteLine("The fields are not equal."); }In this example, the program is comparing two fields of the same class, once again using the Equals function to determine whether they are the same or not. Package/library: System.Reflection