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

Ho we can see assembly information?

523


What is overloading with example?

503


Which debugging tools you can use in the .NET ssSDK?

553


What is generic types in c#?

511


What is void method?

491






What is difference between code access and role based security?

510


Give some examples of commonly used i/o classes?

500


Can datetime be null c#?

490


Can dictionary have duplicate keys c#?

505


What is iqueryable in c#?

496


Constructor to an arbitrary base constructor?

563


What is continue in c#?

518


Why is aws serverless?

501


What are sessions in c#?

496


What is the difference between finally and finalize block?

514