c# - How to order a list with a method in a collection class -
i having problem searching method. want make function inside collection class can find products (objects) in list specific name , there after sort list price.
but because generic can't "reach" fields in objects in list. can please me?
here have tried:
public class productlist<t> : icollection<t>, icomparer<t> { public list<t> _productlist = new list<t>(); // other methods // 1. try: public void funcsearch_name(string search_name, productlist<product> listin, out productlist<product> listout) { listout = listin.where(x => x.name.equals(search_name)).tolist(); // here complaining cant not implicity convert generic list productlist (i dont understand that) } // have tried this: public void funcsearch_name(string search_name, ref list<t> listin, out list<t> listout) { listout = listin.where(x => x.name.equals(search_name)).tolist(); listout.orderbydescending(o => o.price).tolist(); // here can't find name , price because "t" not contains them.. } }
thank time. hope understand problem , can me.
why not make productlist limit t
interface (or concrete product)?
public class productlist : icollection<iproduct>, icomparer<iproduct>