code_junkie

Are “out” parameters a bad thing in .NET?

Nov 12th, 2011
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. void doSomeThing(Thing toDoItTo,
  2. out OtherThing result1,
  3. out AnotherThing result2)
  4. {
  5. ...
  6. }
  7.  
  8. OtherThing y;
  9. AnotherThing z;
  10.  
  11. doSomeThing(x, out y, out z);
  12.  
  13. y.method1();
  14. z.method2();
  15.  
  16. struct DoSomeThingResults
  17. {
  18. public OtherThing Result1;
  19. public OtherThing Result2;
  20. }
  21.  
  22. DoSomeThingResults doSomeThing(Thing toDoItTo)
  23. {
  24. ...
  25. }
  26.  
  27. DoSomethingResults results = doSomeThing(x);
  28.  
  29. results.Result1.method1();
  30. results.Result2.method2();
  31.  
  32. let success, value = Int32.TryParse("1234")
  33. (* success is true *)
  34. (* value is 1234 *)
Add Comment
Please, Sign In to add comment