使用双冒号的c#函数参数的含义?
Meaning of c# function parameter using double colon?
似乎在 c# 中你可以调用一个函数并向它传递一个带有双冒号语法的变量,如下所示:foo(bar: "example")
,这种语法叫什么?
并且,
在下面的 GetReleasesAsync
函数调用中,通过 expand:
我想传递两个变量,而不是像下面那样只传递一个变量,传递多个变量的语法是什么?例如像 expand: {ReleaseExpands.Variables, ReleaseExpands.Artifacts}
带(大)括号的东西?
List<WebApiRelease> azureReleases = await ReleaseHttpClient.GetReleasesAsync(project: _projectName, expand: ReleaseExpands.Variables, top: 100);
Named Arguments
是您在第一个问题中要查找的内容。它是更多的语法糖,导致“更好”的可读性。
expand
是一个标志枚举。因此 expand: ReleaseExpands.Variables | ReleaseExpands.Artifacts
应该作为参数值来提供这两个值。
喜欢
List<WebApiRelease> azureReleases = await ReleaseHttpClient.GetReleasesAsync(project: _projectName, expand: ReleaseExpands.Variables | ReleaseExpands.Artifacts, top: 100);
似乎在 c# 中你可以调用一个函数并向它传递一个带有双冒号语法的变量,如下所示:foo(bar: "example")
,这种语法叫什么?
并且,
在下面的 GetReleasesAsync
函数调用中,通过 expand:
我想传递两个变量,而不是像下面那样只传递一个变量,传递多个变量的语法是什么?例如像 expand: {ReleaseExpands.Variables, ReleaseExpands.Artifacts}
带(大)括号的东西?
List<WebApiRelease> azureReleases = await ReleaseHttpClient.GetReleasesAsync(project: _projectName, expand: ReleaseExpands.Variables, top: 100);
Named Arguments
是您在第一个问题中要查找的内容。它是更多的语法糖,导致“更好”的可读性。
expand
是一个标志枚举。因此 expand: ReleaseExpands.Variables | ReleaseExpands.Artifacts
应该作为参数值来提供这两个值。
喜欢
List<WebApiRelease> azureReleases = await ReleaseHttpClient.GetReleasesAsync(project: _projectName, expand: ReleaseExpands.Variables | ReleaseExpands.Artifacts, top: 100);