c# - How do I create arrays with different types -


i need array store bool , string pair.

mytype[,] array1 = { {true, "apple"}, {false, "orange"} };  // later in code. (i = 0; < array1.length; i++) {     if(array1[i, 0] == true)     {         console.writeline(array1[i, 1]);     } } 

how above in c# without using collection? if not possible, collection should use?

arrays can't have different datatypes. design principle of arrays. instead, create class/struct , create array/list of class. following,

class myclass { bool flag; string mystr; }  list<myclass> mylist=new list<myclass>(); arraylist arrlist = new arraylist(); //or use option 

you should able access list using foreach in c#.


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -