Reputation: 23
I am super beginner at the programming and have a quick question.
i have this code and i want convert it to IF structure but i confused little bit. Can anybody help me to convert it?
var selectedCategoryId = string.IsNullOrEmpty(categoryId5)
? string.IsNullOrEmpty(categoryId4)
? string.IsNullOrEmpty(categoryId3)
? string.IsNullOrEmpty(categoryId2)
? categoryId1
: categoryId2
: categoryId3
: categoryId4
:categoryId5;
Check it up on google
Upvotes: 1
Views: 107
Reputation: 45947
select the FirstOrDefault()
which is not string.IsNullOrEmpty()
string[] input = { categoryId5, categoryId4, categoryId3, categoryId2, categoryId1 };
var result = input.FirstOrDefault(x => !string.IsNullOrEmpty(x));
Upvotes: 5