Unity/Csharp/linq
提供: 初心者エンジニアの簡易メモ
準備
using System.Linq;
条件一行だけ(fetchRow)
public ScoreDay FindByYyyymmdd(string yyyymmdd) { List<ScoreDay> scores = FindAll(); return scores.FirstOrDefault(score => score.yyyymmdd == yyyymmdd); }
条件複数行(fetchAll)
public IEnumerable<ScoreDay> FindAllByYyyymmdd(string yyyymmdd) { List<ScoreDay> scores = FindAll(); return scores.Where(score => score.yyyymmdd == yyyymmdd); }
順序
User[] users = new User[] { new User() { age = 10, name = "taro" }, new User() { age = 13, name = "jiro" }, new User() { age = 12, name = "saburo" }, new User() { age = 15, name = "siro" }, }; // 年下順 IOrderedEnumerable<Parameter> orderedUsers = users.OrderBy( value => value.age ); // 年上順 IOrderedEnumerable<Parameter> orderedUsers = users.OrderByDescending( value => value.age );