C# Default Parameters

前端 未结 4 1365
闹比i
闹比i 2020-12-30 08:32

This is, probably, a very simple answer for someone. I have a method with an Optional Parameter like so;

public static Email From(string emailA         


        
4条回答
  •  失恋的感觉
    2020-12-30 09:11

    Optional parameters have been supported in the CLR since 1.0. Languages like VB.Net's have been using them since the start. While the first version of C# to support them is 4.0, it can still generate valid code for a 2.0 CLR and in fact does so. Hence you can use default parameters in 2010 if you are targeting the 3.5 CLR (or 2.0, 3.0, etc ...)

    This type of support is not limited to default parameters. Many new C# features can be used on older version of the framework because they do not rely on CLR changes. Here are a few more which are supported on CLR versions 2.0 and above

    • Named Arguments: Added C# 4.0
    • Lambda Expressions: Added C# 3.0
    • Auto Properties: Added C# 3.0
    • Extension Methods: Added C# 3.0
    • Co/Contra Variance: Added C# 4.0

提交回复
热议问题