Difference between out and [Out]

Hi

Does anybody know what is the difference between out and [Out]

For example if I'm passing byte[] to unmanaged c++ and I use

fun(out byte[] bArray); // this doesn't work

fun(ref byte[] bArray); // doesn't work too

fun([Out] byte[] bArray); // this work perfectly

C++
fun(*byte);




Answer this question

Difference between out and [Out]

  • MikeOzz

    Thanks for you answer, But tell me if I you [Out] - it does mean that c++ will be using copy of my data - I don't think so couse I can change this data and retrive them in c#. So if [Out] isn't by ref how come c++ can change data

    Or I'm wrong and [Out] - pass read only arguments



  • cbretana

    The out keyword is equivalent to the combination [Out] ref. So the difference between out and [Out] is that [Out] by itself doesn't make a byref parameter.



  • Shima20

    It depends on the declaration of the parameter. For example Method([Out]int parameter) isn't going to stop the parameter from being passed by value.

  • Difference between out and [Out]