So I am new to C# and I am having difficulty understanding out
. As opposed to just returning something from a function
using System;
class Retur
The out
keyword is mostly used when you want to return more than one value from a method, without having to wrap the values in an object.
An example is the Int32.TryParse
method, which has both a return value (a boolean representing the success of the attempt), and an out
parameter that gets the value if the parsing was successful.
The method could return an object that contained both the boolean and the integer, but that would need for the object to be created on the heap, reducing the performance of the method.