al.Add(1);al.Add('1');al.Add("1");
al.Add(1);
al.Add('1');
al.Add("1");
a) Compilation Errorb) Code works perfectly - Prints 1 ‘1’ “1” if an Console.Write statement is written.c) System.IndexOutOfRangeExceptiond) System.InvalidCastExceptione) System.StackOverflowExceptionf) System.IO.IOException
Unlike arrays, Arraylist can have objects of different types. So it will work. b.
I used foreach and print every elements with the tostring method, there is no exception and displayed 1 1 1
b) Since ArrayList is not generically typed it should work perfectly
ArrayList is a non-generic collection class. ArrayList can be used to add unknown data i.e. when we do not know the types of data and size of the data.So Code works perfectly - Prints 1 ‘1’ “1” if an Console.Write statement is written.
it will print if it loop trough 1 1 1
Since ArrayList is class belongs to Collection, it will hold the heterogeneous types of data. So No problem will occur and all the values will get stored into ArrayList.
In ArrayList, you can store elements of the same type and of the different types. It belongs to the non-generic collection.
so b is right answer.
please post correct answer… I think code works perfectly.
print 1,1,1
b) code works perfectly- print 1,'1',"1"
in c language array hold only same data elements .But in c sharp we store any type of data in arraylist
b) Code works perfectly & Prints 1 1 1
It prints 1 1 1
System.InvalidCastException
No problem will occur and all the values will get stored into ArrayList