开发者

Optional arguments and InteropServices

I'm using for the firs time optional arguments but I cannot understand difference between those two method definitions:

private void method1([Optional, DefaultParameterValue(string.Empty)] string testString)
{
    //do something
}

private void method2(string testString = "")
{
    //do something
}

definition of method1 needs:

using System.Runtime.InteropServices;
开发者_如何学JAVA

Method2 definition is smaller and needs no import.

Have I to consider something before using one of those method syntax?


Method 1 was present since .NET 1.1.

Method 2 was introduced with C# 4 (C# did not support optional parameters until then).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜