Code equivalent of out or reference parameters in Dart

dart

Solution

This is not possible in Dart. Support for struct value types, ref or val keywords were discussed on the Dart mailing list just like week. Here is a link to the discussion where you should let your desire be known:

https://groups.google.com/a/dartlang.org/d/topic/misc/iP5TiJMW1F8/discussion

The Dart-way would be:

void example() {
  List result = tryFindResult(anObject);
  if (result[0]) {
    processResult(result[1]);
  } else {
    processForNoResult();
  }
}

List tryFindResult(Object obj) {
  if (obj.contains("What I'm looking for")) {
    return [true, aValue];
  }
  return [false, null];
}

Problem

In Dart, how would I best code the equivalent of an (immutable/value/non-object) out or reference parameter? For example in C#-ish I might code: ``` 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; } ```

Original source