I posted this question yesterday asking about a C# 4 client deploying an ASP.NET application to a .NET 3.5 target server and weather C# 3 on the server compiled something or C# 4 on the client.
That scenario was with optional parameters. I know optional parameters have been supported since like .NET 1.1. Why is it that C# 3 compiled IL code is not be able to call C#4 compiled IL code using optional parameters?
Does C# 3 just ignore the optional attribute?
Optional parameters were introduced to C# only in version 4.0. (They were available in .NET earlier in VB).
You're right... The IL is just decorated w/ OptionalAttributes, but it's the calling compiler that decides what to do...
From Richter:
Now, when a compiler sees that you have code calling a method that is missing some arguments, the compiler can ensure that you've omitted optional argumements, grab their default values out of metadata, and embed them...
So it's the CALLING compiler deciding what to do w/ the optionals, not the called c# 4.0 IL...
More on edge cases and how it's the calling method that decides value can be found from Lippert, @ http://blogs.msdn.com/b/ericlippert/archive/2011/05/16/optional-argument-corner-cases-part-three.aspx
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With