Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Program
- {
- static void Main(string[] args)
- {
- HashCodeCheater cheater1 = new HashCodeCheater();
- HashCodeCheater cheater2 = cheater1;
- Console.WriteLine("using virtual GetHashCode 1: " + cheater1.GetHashCode());
- Console.WriteLine("using virtual GetHashCode 2: " + cheater2.GetHashCode());
- Console.WriteLine("using NON virtual GetHashCode 1: " + RuntimeHelpers.GetHashCode(cheater1));
- Console.WriteLine("using NON virtual GetHashCode 2: " + RuntimeHelpers.GetHashCode(cheater2));
- /*
- * Sample output:
- *
- * using virtual GetHashCode 1: 685172186
- * using virtual GetHashCode 2: 659850042
- * using NON virtual GetHashCode 1: 62476613
- * using NON virtual GetHashCode 2: 62476613
- */
- }
- }
- class HashCodeCheater
- {
- private static readonly Random r = new Random();
- public override int GetHashCode()
- {
- return r.Next();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement