Sandeep Soni
What happens when the following elements get inserted in an ArrayList?
  1. al.Add(1);
  2. al.Add('1');
  3. al.Add("1");

a) Compilation Error
b) Code works perfectly - Prints 1 ‘1’ “1” if an Console.Write statement is written.
c) System.IndexOutOfRangeException
d) System.InvalidCastException
e) System.StackOverflowException
f) System.IO.IOException

By Sandeep Soni in C# on Nov 18 2018
  • Tushar Dikshit
    Apr, 2019 18

    Unlike arrays, Arraylist can have objects of different types. So it will work. b.

    • 4
  • Kenny Dong
    Nov, 2018 23

    I used foreach and print every elements with the tostring method, there is no exception and displayed 1 1 1

    • 4
  • Alan Moore
    Nov, 2018 24

    b) Since ArrayList is not generically typed it should work perfectly

    • 2
  • Ashish Gangwar
    Jul, 2022 20

    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.

    • 1
  • Jignesh Kumar
    Mar, 2019 11

    it will print if it loop trough 1 1 1

    • 1
  • Mangesh Kanche
    Dec, 2018 24

    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.

    • 1
  • sameer shaikh
    Feb, 2020 2

    a)Compilation Error

    • 0
  • SANJAY SHARMA
    Oct, 2019 22

    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.

    • 0
  • Muhammad Zubair
    Aug, 2019 4

    please post correct answer… I think code works perfectly.

    • 0
  • Bidyasagar Mishra
    Jul, 2019 11

    print 1,1,1

    • 0
  • sushil kumar
    Mar, 2019 6

    b) code works perfectly- print 1,'1',"1"

    • 0
  • Amir Khan
    Mar, 2019 6

    in c language array hold only same data elements .But in c sharp we store any type of data in arraylist

    • 0
  • Deepak Vishwakarma
    Feb, 2019 22

    b) Code works perfectly & Prints 1 1 1

    • 0
  • Nikki Nagarkar
    Feb, 2019 5

    It prints 1 1 1

    • 0
  • Amit Prakash
    Jan, 2019 2

    System.InvalidCastException

    • 0
  • Amit Prakash
    Jan, 2019 2

    No problem will occur and all the values will get stored into ArrayList

    • 0


Most Popular Job Functions


MOST LIKED QUESTIONS