c# - Randomly select row of data using linq statement -


hi there have table called word table. following fields: wordid, word, hint, category. table has 40 rows of data. randomly select row of data matches criteria. heres code:

public list<wordtable> get(string diff, string cat) {     using(entities obj = new entities())     {         var qry = (from c in obj.wordtables c.difficultylevel == diff                                                    && c.category == cat select c);         return qry.tolist();     }     } 

for random selection can ,

public wordtable get(string diff, string cat) {     var qry = (from c in obj.wordtables           c.difficultylevel == diff && c.category == cat select c);     var list = qry.tolist();     random r = new random()     var element = list [ r.next(0, list.count-1)];     return element; } 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -