3

I've seen both when looking up P/Invoke definitions... sometimes [Out] is used, and sometimes out... I'm assuming they're the same.

Micky
  • 345
  • 1
  • 4
  • 13
  • 1
    `out` and `[out]` both are equivilent both tells the compiler that the object will be initialized inside the function. – Rahul May 30 '13 at 12:21
  • 1
    Wrong answers here, look at the duplicate. – Hans Passant Jun 27 '16 at 00:11
  • I suppose whether the answers here can be considered correct depends on how relaxed the you take the definition of "equivalent" to be. [This answer](https://stackoverflow.com/a/33817457/1404637) suggest to me that the differences probably shouldn't be glossed over. – alx9r Jan 18 '21 at 19:00

2 Answers2

4

They are the equivalent to each other when used in the context of P/Invoke - see OutAttribute.

You can apply the OutAttribute to value and reference types passed by reference to change In/Out behavior to Out-only behavior, which is equivalent to using the out keyword in C#.

James
  • 80,725
  • 18
  • 167
  • 237
1

In addition to James answer, note that the out contextual keyword is used in two contexts:

  • As a parameter modifier in parameter lists

  • In generic type parameter declarations in interfaces and delegates

Source: http://msdn.microsoft.com/en-us/library/t3c3bfhx.aspx

lightbricko
  • 2,649
  • 15
  • 21