Cannot use ternary operator in LINQ query
Posted
by Nissan Fan
on Stack Overflow
See other posts from Stack Overflow
or by Nissan Fan
Published on 2010-06-07T17:10:26Z
Indexed on
2010/06/07
17:12 UTC
Read the original article
Hit count: 187
I can't figure out why I get a Object reference not set to an instance of an object.
error if I use a ternary operator in my LINQ query.
var courses = from d in somesource
orderby d.SourceName, d.SourceType
select new
{
ID = d.InternalCode,
Name = string.Format("{0} - {1}{2}", d.InternalCode, d.SourceName, (d.SourceType.Length > 0 ? ", " + d.SourceType : string.Empty))
};
Any thoughts?
© Stack Overflow or respective owner