MickeyP (20) [Avatar] Offline
#1
Hi Jon, this is a great book thanks. Am I perhaps misreading it or is there a slight contradiction on Section 4.3.3, page 125?

The 7th bullet point says that for unary and binary operators the return type has to be a non-nullable value type. But then in the very next paragraph, the first two lines say that for the unary and binary operators the return type also becocmes nullable.

Cheers, Mickey
jon.skeet (448) [Avatar] Offline
#2
Re: Is there an error in Unary and Binary operator return type page 125
It's not a mistake, but it's perhaps not as clear as it might be.

The bullet is saying that you only get a lifted version of the operator if the "normal" version of the operator has a non-nullable return type. The next paragraph says that the lifted version of the operator ends up with a nullable return type. For instance, let's look at DateTime's "+" operator:

public static DateTime operator+ (DateTime date, TimeSpan interval)

Note that the return type is DateTime, a non-nullable value type. The lifted version is:

public static DateTime? operator+ (DateTime? date, TimeSpan? interval)

Does that help?

Jon
MickeyP (20) [Avatar] Offline
#3
Re: Is there an error in Unary and Binary operator return type page 125
Yes, got it thanks. The example really helps clarify whats going on.

Thanks for the really prompt reply, I'm still working my way thru chapter 4! smilie

Cheers, Mickey
jon.skeet (448) [Avatar] Offline
#4
Re: Is there an error in Unary and Binary operator return type page 125
Glad it's sorted - if I get time, I'll add a note to the C# in Depth website.

Enjoy the rest of the book, and do feel free to ask if you have any other questions smilie