Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Argument Labels in C#

Tags:

Is there a way in C# to be able to refer to a a parameter by both an internal and external name (in Swift this is known as argument labels/parameters)?

What I mean is suppose I have the following:

public static class Sport
{
    public static void Print(int id sportID)
    {
        Console.Out.WriteLine(sportID);
    }
}

public static void main()
{
    Sport.Print(id: 123);
}

Internally, I refer to the id as sportID, but externally, the parameter is known as id.

like image 323
Mitch Stewart Avatar asked Oct 03 '16 16:10

Mitch Stewart


1 Answers

A little late to the game, but I was looking for something like this as well. It is not exactly what the OP is after, but I think it is close enough.

The parameter names that are set when you declare the methods can be called when calling the method.

Declaring the method:

   static string[] Roster(int numberOfDaysOff, int daysOfStartOnDay) {
      // Method logic with the set names
   }

Calling the method:

Roster(numberOfDaysOff: daysOff,daysOfStartOnDay: startDay);

Hope this helps future readers :-)

like image 62
jwknz Avatar answered Oct 03 '22 00:10

jwknz