Last active
December 19, 2017 11:18
-
-
Save Kazuki-Kachi/4fa715bed93d752a5dbdff734903062d to your computer and use it in GitHub Desktop.
For blog
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Type of conditional expression cannot be determined because there is no implicit conversion between 'lambda expression' and 'lambda expression' | |
Func<int, int> f = args.Any() && int.TryParse(args.First(), out var i) ? x => x + i : x => x; | |
// 型を書いても無駄 | |
Func<int, int> f1 = args.Any() && int.TryParse(args.First(), out var i) ? (int x) => x + i : (int x) => x; | |
// OK : args.Any() && int.TryParse(args.First(), out var j) ? (Func<int, int>)(x => x + j) : x => x の型が `Func<int, int>` に確定するので | |
Func<int, int> f2 = args.Any() && int.TryParse(args.First(), out var j) ? (Func<int, int>)(x => x + j) : x => x; | |
var f3 = args.Any() && int.TryParse(args.First(), out var k) ? (Func<int, int>)(x => x + k) : x => x; | |
// OK : この'lambda expression'と `Func<int, int>` との間には implicit conversion が成立する | |
Func<int, int> f4 = x => x + (args.Any() && int.TryParse(args.First(), out var arg) ? arg : 0); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment