What does "out" do in C# and what is the difference of the pointer?

Asked

Viewed 111 times

3

I was playing Space Engineers and it is possible to add custom codes, called in-game script, in C#. Finally, I came across the need to use such a out, but I didn’t understand what he does and why he exists.


One of the functions is exactly:

float Velocidade = 0;

if (!float.TryParse(Argumentos.Argument(1), out Velocidade)) {
      // ...
}

// ...

When I tried to use the TryParse Visual Studio simply pointed out an error and suggested using out, getting out Velocidade (or instead of Velocidade or &Velocidade).

The code worked. But I still don’t understand why the out exists and what it actually does (and what advantage it has), with C# allowing pointers, as far as I am aware.


Anyway, what does the out and why use it? Why not use pointers?

  • The modifier out in a parameter means that the purpose of that parameter is to return data by the method.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.