c# - Display all strings in a List -
i trying create 2 sets , put both in list , display items in list. getting error code. error: system.collections.generic.list1[system.collections.generic.sortedset
1[system.string]] attaching code below. appreciated.
namespace prog 5 { class program { static void main(string[] args) { list<sortedset<string>> items = new list<sortedset<string>>(); sortedset<string> set = new sortedset<string>(); sortedset<string> set2 = new sortedset<string>(); set.add("a"); set.add("b"); set.add("d"); set.add("c"); set2.add("e"); set2.add("d"); set2.add("c"); foreach (string item in set) { items.add(set); } foreach (string item in set2) { items.add(set2); } displayitem(items); } public static void displayset(sortedset<string> set) { string set1 = string.join(",", set); console.writeline(set1); console.readline(); } public static void displayitem(list<sortedset<string>> items) { foreach (sortedset<string> item in items) { console.writeline(items); console.readline(); } } }
in displayitem(...) have console.writeline(items)... type list>. tostring() automatically gets called on produce string console.writeline output: that's why current message. i'm guessing want write each item console.
public static void displayitem(list<sortedset<string>> items) { foreach (sortedset<string> item in items) { displayset(item); } }
Comments
Post a Comment