Lambda "if" statement?
Posted
by AndyC
on Stack Overflow
See other posts from Stack Overflow
or by AndyC
Published on 2010-03-19T10:56:53Z
Indexed on
2010/03/19
11:01 UTC
Read the original article
Hit count: 147
I have 2 objects, both of which I want to convert to dictionarys. I use toDictionary<>().
The lambda expression for one object to get the key is (i => i.name). For the other, it's (i => i.inner.name). In the second one, i.name doesn't exist. i.inner.name ALWAYS exists if i.name doesn't.
Is there a lambda expression I can use to combine these two? Basically to read as:
"if i.name exists then set id to i.name, else set id to i.inner.name".
Many thanks.
© Stack Overflow or respective owner