Can you store multiple datatypes in an Array?

 Posted by Syedshakeer on 9/14/2009 | Category: C# Interview questions | Views: 20190
Select from following answers:
  1. True
  2. False
  3. Maybe
  4. All Above

Show Correct Answer


Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Posted by: Btomas on: 7/9/2012 | Points: 10
Cannot agree with an answer because you can store multiple types to object array:

public void Main()
{
List<string> cls = new List<string>();
cls.Add("teste");
object[] b = new object[101];
b(0) = true;
b(1) = 240;
b(2) = cls;
b(3) = "bubby";

List<string> clsC = b(2);
Console.WriteLine(clsC.Item(0));
Console.WriteLine(b(3));
Console.WriteLine(Information.TypeName(b(0)));
Console.WriteLine(Information.TypeName(b(1)));
Console.Read();
}

and results would be:
teste
bubby
Boolean
Integer


So the answer is wrong and should be "true if used Object array otherwise is false" or the question is badly formulated.

Login to post response