Alex Rivera | Logout

Introduction to C# list comprehensions

Asked 2008-09-25T01:03:25.807
70

How can I perform list comprehensions in C#?

Edit
Report

1 Answer

-9

While this isn't a tutorial, here's some code that illustrates the concept:

public List<string> ValidUsers(List<User> users) {
  List<string> names = new List<string>();
  foreach(User user in users) {
    if(user.Valid) {
      names.Add(user.Name);
    }
  }
  return names;
}
answered 2008-09-25T01:08:48.850

Your Answer