GetHashCode method in ArrayList

In this article I will explain the GetHashCode method of ArrayList.
  • 2356

Introduction

The GetHashCode method of ArrayList serves as a hash function for a particular type.The GetHashCode method returns the hashcode of the variable and the operation that we perform.

Example

namespace ConsoleApplication6

{

    class Program

    {

        static void Main(string[] args)

        {

            //create the arraylist named days

            ArrayList days = new ArrayList();

            //add the elements in the arraylist

            var a = days.Add("Sunday");

            var b = days.Add("Monday");

            var c = a | b; //perform or operation between a and b index values

            var d = a & b; //perform add opeartion between a and b index values

            var e = a ^ b; //perform Xor operation

            days.Add("Tuesday");

            days.Add("Wednesday");

            days.Add("Thusday");

            days.Add("Friday");

            days.Add("Saturday");

            Console.WriteLine("The hashcode of varaible a is:" + a.GetHashCode());

            Console.WriteLine("The hashcode of varaible b is:" + b.GetHashCode());

            Console.WriteLine("The hashcode of varaible c is:" + c.GetHashCode());

            Console.WriteLine("The hashcode of varaible d is:" + d.GetHashCode());

            Console.WriteLine("The hashcode of varaible e is:" + d.GetHashCode());

        }

    }

}

 

Output

hashcode.jpg 

 

Ask Your Question  

Got a programming related question? You may want to post your question here
 

Categories

More Articles

© 2019 DotNetHeaven. All rights reserved.