GetType method in ArrayList
In this article I will discuss the GetType method of ArrayList.
Introduction
GetType method of ArrayList gets the type of the current instance, means if we create two arraylist with different objects then the type of object is the arraylist so it gives true,as we declare two arraylist and compare it,if we compare the arraylist with some other collection like stack then the gettype gives the results as false.
Example
public class MyArrayList
{
public static void Main()
{
// Creates a new ArrayList.
ArrayList myArray = new ArrayList();
myArray.Add("one");
myArray.Add("two");
myArray.Add("three");
myArray.Add("four");
myArray.Add("five");
//create the another arraylist
ArrayList myArray1 = new ArrayList();
myArray1.Add("six");
myArray1.Add("seven");
myArray1.Add("eight");
myArray1.Add("nine");
myArray1.Add("ten");
//create the new collection say stack
Stack stack = new Stack();
stack.Push("xyz");
stack.Push("PQR");
//perform gettype method
Console.WriteLine("myArray and myArray1 are the same type: {0}",
Object.ReferenceEquals(myArray.GetType(), myArray1.GetType()));
Console.WriteLine("myArray and stack are the same type: {0}",
Object.ReferenceEquals(myArray.GetType(), stack.GetType()));
}
}
|
Output

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