Can you store multiple data types in System.Array?
Answers were Sorted based on User's Feedback
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 |
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 |
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 |
Answer / ankur
yes we can store multiple datatype in system.array in c#
Is This Answer Correct ? | 0 Yes | 0 No |
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 |
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 |
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 |
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 |
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 |
Can you explicitly call a destructor?
What is a string in c#?
Can a structure be inherited by a class?
Why is it not a good idea to insert code into InitializeComponent method when working with Visual Studio ?
What is float in unity?
how to add datarow to datatable
list the steps in code compilation in c#?
What's the difference between the debug class and trace class? Documentation looks the same.
What is the use of functional interface?
What is the difference between abstraction and encapsulation in c#?
What is marshalling and what are different kinds of marshalling?
What are three test cases you should go through in unit testing?
1 Answers Siebel Systems, Wipro,