c# - Unable to get result using object -


public object my() {     list<string> mystring = new list<string>();     mystring.add("aaaa");     mystring.add("bbb");                return mystring;    } 

in main

 program p1 = new program();  object test = p1.my();  console.writeline(test); 

even if converted tolist() i'm getting system.collection.generic.list

how convert result list , display elements?

you need cast object (test) list<string> , iterate on elements in list<string> print them.

try this:

program p1 = new program(); object test= p1.my();  list<string> lst = (list<string>) test; foreach(string item in lst)    console.writeline(item); 

Comments

Popular posts from this blog

android - Gradle sync Error:Configuration with name 'default' not found -

java - Andrioid studio start fail: Fatal error initializing 'null' -

html - jQuery UI Sortable - Remove placeholder after item is dropped -