We're going to discuss about arrays.When someone asks a question regarding to arrays then You always tell him/her the same story i.e., array is used to hold variable of same data type.
And if the interviewer ask you to tell the difference between array and list then you always tell him/her the story that array is used to hold variable of same data type and list is for different data types.
But what if the interviewer ask you to implement the array that hold different data types.
Now you become shocked that how it could be possible? Even many developers with good experience in the field of programming becomes confuse with this tricky question.
So here is the solution of this i.e., polymorphic array.
First create a simple Console Application in Visual Studio and name it whatever you want. Now what you'll need is simply add a following lines of code into your console application.
object[] array = new object[4];
array[0] = 123;
array[1] = "Asfend";
array[2] = 12.3;
array[3] = 3658.98;
foreach (var item in array)
{
Console.WriteLine(item);
}Now try to Run you project and you'll notice that you've successfully create an array that will allow you to store variables of different data types.