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 primitive types in c#?
What are the 2 kinds of data type conversions in c#?
What are the examples of data types?
Wats the diff between sealed class and private class in inheritance
Is for loop faster than foreach?
What is the difference between String s(Small s) and String S(Capital S)?
How long can loop recorders stay in?
Can struct be static in c#?
How did you implemented classes in your project?
what are the events in delegate?
Is IIS is required for installing the deployment of windows C#.netapplication and to run.
Is array a collection c#?
Visual Basic (800)
C Sharp (3816)
ASP.NET (3180)
VB.NET (461)
COM+ (79)
ADO.NET (717)
IIS (369)
MTS (11)
Crystal Reports (81)
BizTalk (89)
Dot Net (2435)
Exchange Server (362)
SharePoint (720)
WCF (340)
MS Office Microsoft (6963)
LINQ Language-Integrated Query (317)
WPF (371)
TypeScript (144)
Microsoft Related AllOther (311)