How to return object using list c# -
i have class item.cs , want homecoming items base of operations list<item>
,....
so here code webservice1.asmx
[webmethod] public list<item> getmyitems() { list<item> listofitems= new list<item>(); item add together = new item(); using (var db = new baza()) // in database (this works fine) { var lookup = in db.listofitems select new { id = a.id, name = a.name, year= a.year, price= a.price }; foreach (var item in lookup) { if (item.name == "usb") { add.name = item.name; add.year = item.year; add.price = item.price; listofitems.add(add); } } homecoming listofitems; } }
and want utilize object in .cs file. on illustration "program.cs"
so in program.cs phone call method "getmyitems":
list<item> myitems = myservice.getmyitems();
i had include own library class "item.cs"
and on end error:
error 1 cannot implicitly convert type 'myitems.servicereference1.item[]' 'system.collections.generic.list<mylibrary.item>'
my purpose can in program.cs utilize every property(in case: name, year, price) "listview"
for answers in advance thanks.
when utilize method through service automatically cast list<item>
basic info type item[]
.
to work around see 2 options:
use var keyword, , go on using info type item[]
.
var myitems = myservice.getmyitems();
cast ienumerable<item>
:
var myitems = myservice.getmyitems().tolist();
c# list object parameters return
No comments:
Post a Comment