linq - Sorting by age a list class in c# -


i'm beginner , want create implementation prints user information console, ordered age. i've tried use linq without success. code base:

class user {     public string name;     public string surname;     public int age; }  interface usersconsumer { public void consume(list<users> collection); } 

this tried interface:

list<user> sorteduserlist =      collection.orderbydescending(collection => collection.age).tolist(); 

you need use different variable name inside lambda expression like:

list<user> sorteduserlist = collection.orderbydescending(row => row.age).tolist(); 

otherwise end error like:

a local variable named 'collection' cannot declared in scope because give different meaning 'collection', used in 'parent or current' scope denote else

edit: noticed 1 thing:

this tried interface:

you can't have implementation in interface. interface more of contract, have implement interface in class , put implementation like:

public class someclass : usersconsumer  {     public void consume(list<user> collection)     {         list<user> sorteduserlist = collection.orderbydescending(row => row.age).tolist();     } }    

make sure, follow .net naming conventions.


Comments

Popular posts from this blog

java - Oracle EBS .ClassNotFoundException: oracle.apps.fnd.formsClient.FormsLauncher.class ERROR -

c# - how to use buttonedit in devexpress gridcontrol -

nvd3.js - angularjs-nvd3-directives setting color in legend as well as in chart elements -