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
Post a Comment