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 |
What is difference between string and stringbuilder in c#?
What is the difference between double and decimal in c#?
How does the XmlSerializer work ?
What's the difference between System.String and System..StringBuilder in C#?
How do you escape c#?
Illustrate namespaces in c#?
What are extension methods and where can we use them?
Explain 'structure padding'?
How to force my .net app to run as administrator on windows 7?
Name the two classes are required for implementing a windows service?
What is the difference between interface and functional interface?
What are some examples of desktop applications?