Optional arguments and InteropServices

笑着哭i 提交于 2019-12-01 07:32:35

问题


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;

Method2 definition is smaller and needs no import.

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


回答1:


Method 1 was present since .NET 1.1.

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



来源:https://stackoverflow.com/questions/6215579/optional-arguments-and-interopservices

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!