Ok, I'm looking to sort the List (UserList) by the property (WordList), although I need (WordList) to be sorted by a particular property first.
The whole Sort UserList method does not sort the UserList whether I try by (userName) or by the (WordList).(wordName) or (WordList).(amountOfGuesses)
public class User
{
public string userName;
public List<Word> wordList;
public User() { }
public User(string name, String word, int guesses)
{
this.userName = name;
wordList = new List<Word>();
Word theWord = new Word(word, guesses);
this.wordList.Add(theWord);
}
}
public List<User> SortUserList(String g)
{
String option = g.ToLowerInvariant();
switch(option){
case "name":
this.UserList.OrderBy(x=> x.userName);
break;
case "word":
this.UserList.OrderBy(k => k.wordList.OrderBy(w => w.wordName));
break;
case "guess":
this.UserList.OrderBy(m=> m.wordList.OrderBy(y => y.amountOfGuesses));
break;
}
return UserList;
}
public void Test()
{
User xor = new User("xor", "xadfs", 20);
User bob = new User("bob", "char", 3);
User james = new User("james", "adfsad", 200);
UserList.Add(bob);
UserList.Add(james);
UserList.Add(xor);
}
wordListvalues be for your example? Could you paste the definition ofUser(its constructors and properties)?