c# - How to create multidimensional array with multitype? -


i used create kind of arrays in php:

$myarray[0]["my_string_1"] = "toto"; $myarray[0]["my_string_2"] = "tata"; $myarray[0]["my_int_1"] = 25; $myarray[0]["my_int_2"] = 28; $myarray[1]["my_string_1"] = "titi"; $myarray[1]["my_string_2"] = "tutu"; $myarray[1]["my_int_1"] = 12; $myarray[1]["my_int_2"] = 15; 

my question is: possible same thing in c#?

not familiar php looks array has 'map' of string string or int. can done in c# using dictionary , dynamic:

var myarray = new dictionary<int, dictionary<string, dynamic>>() {     {         0, new dictionary<string, dynamic>()         {             {"my_string_1", "toto"},             {"my_string_2", "tata"},             {"my_int_1", 25},             {"my_int_2", 28},         }     },     {         1, new dictionary<string, dynamic>()         {             {"my_string_1", "titi"},             {"my_string_2", "tutu"},             {"my_int_1", 12},             {"my_int_2", 15},         }     } }; 

see documentation more info on dictionary , dynamic.

edit:

as others have suggested, might better off using:

var myarray = new dictionary<int, dictionary<string, object>>() 

and instead of using dictionary int key, actual array used:

var myarray = new dictionary<string, object>[2]; myarray[0] = new dictionary<string, object> {      {"my_string_1", "toto"},     {"my_string_2", "tata"},     {"my_int_1", 25},     {"my_int_2", 28}, }; myarray[1] = new dictionary<string, object> {      {"my_string_1", "titi"},     {"my_string_2", "tutu"},     {"my_int_1", 12},     {"my_int_2", 15}, }; 

Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -