如果您使用的是C#3.0,则可以使用linq,效果更好,更优雅:
List<int> myList = GetListOfIntsFromSomewhere();// This will filter out the list of ints that are > than 7, Where returns an// IEnumerable<T> so a call to ToList is required to convert back to a List<T>.List<int> filteredList = myList.Where( x => x > 7).ToList();
如果找不到
.Where,则意味着您需要
using System.Linq;在文件顶部导入。



