简体   繁体   中英

C# CLR/Compiling Question

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

My simple guess would be because the Base Class Libraries are different? This makes the difference between C# 3.* and 4.* much bigger than say 2.* vs 3.* as the latter used the same BCL.

Not sure though.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM