gpt4 book ai didi

c# - 可选参数和 InteropServices

转载 作者:行者123 更新时间:2023-11-30 22:38:09 26 4
gpt4 key购买 nike

我第一次使用可选参数,但我无法理解这两个方法定义之间的区别:

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

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

method1的定义需要:

using System.Runtime.InteropServices;

Method2 定义较小,无需导入。

在使用其中一种方法语法之前,我是否需要考虑一些事情?

最佳答案

自 .NET 1.1 以来就存在方法 1。

方法 2 是在 C# 4 中引入的(C# 直到那时才支持可选参数)。

关于c# - 可选参数和 InteropServices,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6215579/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com