-2

Seemingly in c# you can call a function and pass it a variable with a double colon syntax like so: foo(bar: "example"), what is this syntax called?

And,

in the GetReleasesAsync function call below, by the expand: I would like to pass two variables as opposed passing only one like below, what is the syntax to pass more than one variable? For example something like expand: {ReleaseExpands.Variables, ReleaseExpands.Artifacts} with (curly) brackets?

List<WebApiRelease> azureReleases = await ReleaseHttpClient.GetReleasesAsync(project: _projectName, expand: ReleaseExpands.Variables, top: 100);
Zimbabaluba
  • 588
  • 1
  • 8
  • 24
  • 1
    `Named Arguments` is what you are looking for in your first question. It is more syntactic sugar which leads to a "better" readability. – Daniel Rafael Wosch Jun 07 '21 at 12:26
  • 1
    And for the second part: I think what you are looking for is a bit pattern, i.e. the combination of several input flags. This is done by separating the flags with a pipe sign. That is: expand: ReleaseExpands.Variables | ReleaseExpands.Artifacts – rmfeldt Jun 07 '21 at 12:32
  • @rmfeldt the pipe sign is just what I needed! Ty. – Zimbabaluba Jun 07 '21 at 12:33

1 Answers1

2

Named Arguments is what you are looking for in your first question. It is more syntactic sugar which leads to a "better" readability.

expand is a Flags enum. therefore expand: ReleaseExpands.Variables | ReleaseExpands.Artifacts should work as parameter value to provide both values.

Like

List<WebApiRelease> azureReleases = await ReleaseHttpClient.GetReleasesAsync(project: _projectName, expand: ReleaseExpands.Variables | ReleaseExpands.Artifacts, top: 100);
  • 2
    `It is more syntactic sugar which leads to a "better" readability.` It also makes passing a later optional argument without specifying an earlier one possible. Which isn't really a _readability_ issue. – mjwills Jun 07 '21 at 12:35