The requested page is not available for the requested platform. You are viewing the content for Default platform.

Use Named Arguments

  • 2 min read

Converts a method call with positional arguments into a named-argument call.

Availability

Available from the context menu or via shortcuts:

  • when the caret is on a method name within its call, provided that the method has parameters.

Example

private List<UserInfo> _Users;
public void AddUser(string name, string familyName, DateTime birthDate)
{
    if (_Users == null)
        _Users = new List<UserInfo>();
    _Users.Add(new UserInfo(name, familyName,birthDate));
}
private void TestMethod()
{
    DateTime bDate = new DateTime(1980, 12, 25);AddUser("UserName", "UserFamilyName", bDate);
}
Private _Users As List(Of UserInfo)
Public Sub AddUser(name As String, familyName As String, birthDate As DateTime)
    If (_Users Is Nothing) Then
        _Users = New List(Of UserInfo)
    End If
    _Users.Add(New UserInfo(name, familyName, birthDate))
End Sub
Private Sub MethodName()
    Dim bDate As DateTime = New DateTime(1980, 12, 25)AddUser("UserName", "UserFamilyName", bDate)
End Sub

Result:

private List<UserInfo> _Users;
public void AddUser(string name, string familyName, DateTime birthDate)
{
    if (_Users == null)
        _Users = new List<UserInfo>();
    _Users.Add(new UserInfo(name, familyName,birthDate));
}
private void TestMethod()
{
    DateTime bDate = new DateTime(1980, 12, 25);
    AddUser(name: "UserName", familyName: "UserFamilyName", birthDate: bDate);
}
Private _Users As List(Of UserInfo)
Public Sub AddUser(name As String, familyName As String, birthDate As DateTime)
    If (_Users Is Nothing) Then
        _Users = New List(Of UserInfo)
    End If
    _Users.Add(New UserInfo(name, familyName, birthDate))
End Sub
Private Sub MethodName()
    Dim bDate As DateTime = New DateTime(1980, 12, 25)
    AddUser(name:="UserName", familyName:="UserFamilyName", birthDate:=bDate)
End Sub

Screenshot

rsUseNamedArguments