Why can't I use a ternary operator with this expression?

In C#, every conditional expression must have a type. What type is your expression of? I understand your concern, the conversion is not needed for your particular case, but this is how C# compiler works, so you have to obey its rules This should work instead (I didn't check though): dict.

Add("breakit", myDate. HasValue? (object)myDate.

Value : (object)DBNull. Value).

In C#, every conditional expression must have a type. What type is your expression of? I understand your concern, the conversion is not needed for your particular case, but this is how C# compiler works, so you have to obey its rules.

This should work instead (I didn't check though): dict. Add("breakit", myDate. HasValue?(object)myDate.

Value : (object)DBNull. Value).

My expression should be of either type System. DateTime or DBNull depending on the condition of myDate. Value – scottm Jun 28 at 14:10 Casting to object does work.

– scottm Jun 28 at 14:11 then it's not a static type, but a dynamic type. C# compiler is static-typed (apart from some dynamic mechanics I'm not fully sure about). – Zruty Jun 28 at 14:13 7 It is actually not true that every expression must have a type, but it is true that every conditional expression must have a type.

There are four expressions in C# that have no type. The null literal, a lambda, an anonymous method, and a method group. In each case, the type information flows from the context to the expression rather than from the expression outwards, as it normally does.

– Eric Lippert Jun 28 at 14:22 Thank you for the clarification, +1 – Zruty Jun 28 at 15:11.

Date = myDate. HasValue?MyDate. Value : null; dict.

Add("breakit", date).

This gives the same error. – scottm Jun 28 at 14:14 Even though, I don't understand why do we need to cast to object when it is the master base class! – LordCover Jun 28 at 14:18.

In C#, every conditional expression must have a type. What type is your expression of? I understand your concern, the conversion is not needed for your particular case, but this is how C# compiler works, so you have to obey its rules.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions