Created
January 30, 2010 07:18
-
-
Save miya2000/290464 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| private void Hoge(string kubun) | |
| { | |
| var dataList = new[] { | |
| new { Value1 = "aaa", Value2 = (string)null }, | |
| new { Value1 = "bbb", Value2 = (string)null }, | |
| new { Value1 = (string)null, Value2 = "aaa" }, | |
| new { Value1 = (string)null, Value2 = "bbb" }, | |
| }; | |
| var data1 = dataList.First(n => kubun == "1" ? n.Value1 == "aaa" : n.Value2 == "bbb"); | |
| //Compile Error. | |
| //var data2 = dataList.First(kubun == "1" ? n => n.Value1 == "aaa" : n => n.Value2 == "bbb"); | |
| var data3 = (kubun == "1") | |
| ? dataList.First(n => n.Value1 == "aaa") | |
| : dataList.First(n => n.Value2 == "bbb"); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment