multiple data types in array

Posted by Abhisekjani under C# on 3/24/2011 | Points: 10 | Views : 6832 | Status : [Member] | Replies : 2
Can we store multiple data types in System.Array?If possible how it be.?




Responses

Posted by: SheoNarayan on: 3/24/2011 [Administrator] HonoraryPlatinum | Points: 25

Up
0
Down
Ideally no, you can create an array of a data type and you will only be able to store that type of data into that array. However you can create an array of object

object[] myObjA = new object[3] { 5, 6, "7" };

and may store any types of data by converting them to an array. Theoretically, it may look possible but would suggest not to do it.

Instead you can use ArrayList that accepts data in the form of object and virtually you can add anything into it.

Thanks

Regards,
Sheo Narayan
http://www.dotnetfunda.com

Abhisekjani, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Madhu.b.rokkam on: 3/24/2011 [Member] [MVP] Bronze | Points: 25

Up
0
Down
Use an Arraylist always for this type of scenario or use var type too..

Thanks and Regards
Madhu

Abhisekjani, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response