传递参数的顺序

问题描述 投票:0回答:1
public static bool SavePhoneInfo(int applicantId, string phoneType, string phoneNumber, string extensionNumber, bool isActive, int userID, out string msg)
{
   DataAccess dal = new DataAccess();
   return dal.SavePhoneInfo(applicantId, phoneType, phoneNumber, extensionNumber,isActive, userID, out msg);
}

我想为extensionNumber参数添加一个默认值,在哪里添加参数? 在out string msg之前还是之后,c#中传递参数的顺序是什么?

c# webforms
1个回答
3
投票

在C#中,你需要把默认参数放在最后。

public static bool SavePhoneInfo(int applicantId, string phoneType, string phoneNumber,  bool isActive, int userID, out string msg, string extensionNumber = "Test")
{
   DataAccess dal = new DataAccess();
   return dal.SavePhoneInfo(applicantId, phoneType, phoneNumber, extensionNumber,isActive, userID, out msg);
}

在C#中,你需要把默认参数放在最后:

© www.soinside.com 2019 - 2024. All rights reserved.