public static void Test() { int[] someInts = new int[] { 1, 2, 3, 17, 34 }; Dictionary <long, bool> is_odd_lookup_2 = someInts.ToDictionary(GetKey, IsOdd); Dictionary <int, bool> is_odd_lookup_1 = someInts.ToDictionary(i => i, i => i % 2 == 1); Lesson_1_testing.Ensure_correct(is_odd_lookup_1); Lesson_1_testing.Ensure_correct(is_odd_lookup_2); // note how the key types are different for illustration - A* pedagog! }
public static void Test() { int[] someInts = new int[] { 1, 2, 3, 17, 34 }; Dictionary <string, bool> is_odd_lookup_1 = someInts.ToDictionary( keySelector: i => $"{i}", valueSelector: i => i % 2 == 1 ); Dictionary <string, bool> is_odd_lookup_2 = someInts.ToDictionary(GetKey, IsOdd); // Note how we used both "function pointers" // and lambdas for key and value selectors. // Either of those works as a Func<>. // (of course also delegates) Lesson_1_testing.Ensure_correct(is_odd_lookup_1); Lesson_1_testing.Ensure_correct(is_odd_lookup_2); }