15. public class Data {
public List<Student> students = new List<Student>();
}
public static int Main() {
Data data = new Data(){ students = さっきのデータ };
IEnumerator<string> linq = data.students.さっきのLinq;
foreach ( var n in linq ) Debug.Log( n );
}
Output:
a
d
16. foreach ( var n in linq ) Debug.Log( n );
var newer = new Student(){
Name = "newer", TestResult = new[]{ 0,0,0 }.ToList() };
students.Add( newer );
foreach ( var n in linq ) Debug.Log( n );
20. var value = datas
.Where( x => filter( x ) ) // 重いフィルター処理
.Select( x => convert( x ) ) // 重いコンバート処理
.FirstOrDefault();
この場合、重いfilterやconvertは
1度しか実行されません
26. foreach ( var x in datas ) {
// ↓ Where( x => filter( x ) )
if ( false == filter( x ) ) continue;
// ↓ Select( x => convert( x ) )
var xx = convert( x );
// ↓ FirstOrDefault()
return xx;
}
return default(T); // ← FirstOrDefault()
と、同義!
33. public class Data {
public List<Student> students = new List<Student>();
}
public static int Main() {
Data data = new Data(){ students = さっきのデータ };
IEnumerator<string> linq = data.students.さっきのLinq;
}
34. public class Data {
public List<Student> students = new List<Student>();
}
public static int Main() {
Data data = new Data(){ students = さっきのデータ };
IEnumerator<string> linq = data.students.さっきのLinq;
}
37. var seq = students
.Where( x => x.TestResult.Average() < 30 )
.Where( x => 3 <= x.Name.Length );
var names = seq.Select( x => x.Name );
var count = seq.Count();