我是编程的超级初学者,有一个快速的问题。
我有这个代码,我想把它转换成IF结构,但我有点困惑。有人能帮我转换一下吗?
var selectedCategoryId = string.IsNullOrEmpty(categoryId5)
? string.IsNullOrEmpty(categoryId4)
? string.IsNullOrEmpty(categoryId3)
? string.IsNullOrEmpty(categoryId2)
? categoryId1
: categoryId2
: categoryId3
: categoryId4
:categoryId5;
在google上查一下
选择非string.IsNullOrEmpty()
的FirstOrDefault()
string[] input = { categoryId5, categoryId4, categoryId3, categoryId2, categoryId1 };
var result = input.FirstOrDefault(x => !string.IsNullOrEmpty(x));