Assuming you actually wanted to replace the if construct (instead of the foreach as stated in your reply to TGC - foreach is the best way to iterate through a List)...
Code:foreach (var name in Students) { switch (name.StudentName.ToLower()) { case "john": // Do something specific to John break; case "alex": // Do something specific to Alex break; case "james": case "robert": // Do something specific to both James and Robert break; default: // Do something if not John, Alex, James, or Robert break; } // If you need - you can do something here common to all }




Reply With Quote