Can you store multiple data types in System.Array?

Answers were Sorted based on User's Feedback



Can you store multiple data types in System.Array?..

Answer / payal mehta

No,we cannot store multiple datatype in Array.we can store
similar datatype in Array,but i think that we can store in
ArrayList class in c#.

Is This Answer Correct ?    8 Yes 8 No

Can you store multiple data types in System.Array?..

Answer / alok yadav

Yes, its possible try the below sample
replace manageAdvertisement with your class

System.Array ar=Array.CreateInstance(Type.GetType
("System.Object"),3);
ar.SetValue("asdfas",0);
ar.SetValue(1, 1);
ManageAdvertisement mg=new ManageAdvertisement();
mg.AdvertisementDesc="123124";
ar.SetValue(mg, 2);
foreach (object obj in ar)
{
Response.Write( obj.GetType() +"<br>");

}

Is This Answer Correct ?    1 Yes 1 No

Can you store multiple data types in System.Array?..

Answer / srikar

No

Is This Answer Correct ?    1 Yes 1 No

Can you store multiple data types in System.Array?..

Answer / ajeet singh

yes, we can store different data type in System.array.
for do this we have to create the array of OBJECT type.....

Is This Answer Correct ?    0 Yes 0 No

Can you store multiple data types in System.Array?..

Answer / ankur

yes we can store multiple datatype in system.array in c#

Is This Answer Correct ?    0 Yes 0 No

Can you store multiple data types in System.Array?..

Answer / suyash

ideally we don't,, but we can....
we can do this by declaring object in array which can be
used for different data types!!!

Is This Answer Correct ?    0 Yes 0 No

Can you store multiple data types in System.Array?..

Answer / shamjeet

yes,ofcourse
System.Array is of Object Type
eg:
int a =10;
float b=2.03;
string c = "yes"
object[] val = new object[3];
val[0] = a;
val[1] = b;
val[2] = c;

Is This Answer Correct ?    0 Yes 0 No

Can you store multiple data types in System.Array?..

Answer / michael

No you can't ArrayList stores object. So if you use something like this
ArrayList arr = new ArrayList();
arr.Add(56);
arr.Add("ASDf");

you are still storing objects, 56 is object, ASDf is an object

Is This Answer Correct ?    0 Yes 0 No

Can you store multiple data types in System.Array?..

Answer / surya

No you can not. But if you use System.Collection.ArrayList
then you can store multiple data types in ArrayList but not
in case of System.Array.

Is This Answer Correct ?    3 Yes 5 No

Can you store multiple data types in System.Array?..

Answer / srivathsan

i guess you cannot do that in a list too. because an array
list is also type safe.
eg:

List<int> arraylist = new List<int>();

the arraylist can contain only integer items.You cannot
store an item that is not an integer type in the arraylist.

Is This Answer Correct ?    4 Yes 7 No

Post New Answer

More C Sharp Interview Questions

Can you explicitly call a destructor?

0 Answers  


What is a string in c#?

0 Answers  


Can a structure be inherited by a class?

3 Answers  


Why is it not a good idea to insert code into InitializeComponent method when working with Visual Studio ?

1 Answers  


What is float in unity?

0 Answers  






how to add datarow to datatable

1 Answers  


list the steps in code compilation in c#?

0 Answers  


What's the difference between the debug class and trace class? Documentation looks the same.

0 Answers  


What is the use of functional interface?

0 Answers  


What is the difference between abstraction and encapsulation in c#?

0 Answers  


What is marshalling and what are different kinds of marshalling?

0 Answers  


What are three test cases you should go through in unit testing?

1 Answers   Siebel Systems, Wipro,


Categories