I looked at the sources and found that one of the arguments to the FileStream Read method has the [In, Out] modifier.

 [System.Security.SecuritySafeCritical] // auto-generated public override int Read([In, Out] byte[] array, int offset, int count) { } 

What does this modifier mean?

If you believe MSDN, it is used to interact with COM, but there seems to be no COM interaction in this method.

  • The direction of data movement. You input an array to it, and the method changes it. In MSDN, it is very often for WinAPI - Vladimir Martyanov
  • And through ref this behavior can not be achieved? - iluxa1810
  • And who knows, I don't write on .NET ... - Vladimir Martyanov
  • @ iluxa1810: And byte[] - reference type, with it you can transfer data and so. The point is that COM needs to be prompted if it is allowed to read ( [In] ) or write ( [Out] ) for this data. - VladD
  • five
    @ iluxa1810, let's start with the fact that these are not modifiers, but attributes. In C #, there are modifiers of the out and ref parameters, which can confuse you if you tried to read about them somewhere - Qutrix

1 answer 1

OutAttribute — Indicates that marshaling of data from the called object to the caller is required.


InAttribute — Indicates what data must be marshaled during transmission from the caller to the callee, but not the reverse.

These attributes can be applied to parameters. The InAttribute and OutAttribute are optional. These attributes are only supported for COM interop and unmanaged code invocation.

More details can be read on MSDN:

  1. OutAttribute - class
  2. InAttribute - class

Pay attention to the Notes and Examples by clicking on the links.