【发布时间】:2019-07-31 17:11:15
【问题描述】:
我是 C# 新手,对 out 参数修饰符的工作原理有点困惑。
我有这个功能
public static void GuidUnsmash(string smashed, out Guid first, out Guid second)
{
if (smashed.Length != 64)
{
throw new ArgumentOutOfRangeException();
}
string firstGuid = smashed.Substring(0, 32);
string secondGuid = smashed.Substring(32, 32);
first = new System.Guid(firstGuid);
second = new System.Guid(secondGuid);
}
我试图用这个来调用它
[HttpGet]
public async Task<ActionResult> Pending(string pendingticket)
{
// CAR-AAR built with PersonId and MonerisID in ticket, this was overkill, just needed the MonerisID
GuidHelpers.GuidUnsmash(pendingticket, out Guid personId, out Guid monerisId); //this is the line that has the error
var preload = await MonerisApplicationRepository.PrepareTransactionForMonerisPreload(monerisId);
var preloadResponse = await MonerisRepository.PostPreloadTransactionRequest(preload);
var persistPreload = await MonerisApplicationRepository.PersistMonerisPreloadTransactionResponse(monerisId, preloadResponse);
var transactionRequest = preloadResponse.ToMonerisPreAuthorization();
//var viewPendingRequest = new MonerisPendingPreloadTransaction(transactionRequest, preload);
// View redirects to Moneris with autosubmit to begin preauthorization process.
return View(transactionRequest);
}
但是我收到一个错误,提示 GuidUnsmash 没有重载方法。这让我很困惑,因为它们都有相同数量的参数。
【问题讨论】:
-
请提供minimal reproducible example,以便我们重现问题。确保包含确切错误消息。
-
@RufusL @Christopher 您可以在方法调用docs.microsoft.com/en-us/dotnet/csharp/whats-new/… 中内联
out变量声明 -
任何时候您“遇到错误”都需要告诉我们错误是什么。
-
你的方法编译并可以调用。 ideone.com/5UNthu该错误是由您未在问题中显示的代码引起的。
-
在描述特定错误或异常时,请按原样剪切并粘贴实际错误消息。自己解释错误可能会引起很多混乱,而原始错误消息通常是可搜索的。