Can you store multiple data types in System.Array?

Answer Posted / sudhir sheoran

The answer is yes and no.
Ideally array is collection of single data types
E.g :-
array [] arr = new int [10];
it will store only int because datatype is defined
as int in this case.

In case of some particular requirements array can be used
to store diff data types. But in this case array has
to be declared as object array
E.g:-
class Test
{
public static void Main()
{
object[] arr = new object[10];
arr[0] = 1;
arr[1] = "Hello";
Console.WriteLine(arr[0]);
Console.WriteLine(arr[1]);
Console.ReadLine();
}
}
This is successfully complied.

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What's the difference between System.String and System..StringBuilder in C#?

496


How do you create dlls in .NET

568


What is msil in c#?

538


What is a delegate? Explain.

534


What is the difference between dataset and datatable in c#?

541






Is stringbuilder thread safe c#?

473


What is the difference between namespace and class in c#?

498


What is a struct in C#?

555


what is an exception in .net?

510


Is c# and c same?

505


What is stringwriter c#?

433


What is int32?

483


What is the use of command builder?

531


What is the purpose of a constructor in c#?

457


Why do we need to override in c#?

517