在 Dart 中,我如何最好地编写等效于(不可变/值/非对象)输出或引用参数的代码?
例如在 C#-ish 中,我可能会编码:
function void example()
{
int result = 0;
if (tryFindResult(anObject, ref result))
processResult(result);
else
processForNoResult();
}
function bool tryFindResult(Object obj, ref int result)
{
if (obj.Contains("what I'm looking for"))
{
result = aValue;
return true;
}
return false;
}
Run Code Online (Sandbox Code Playgroud) dart ×1