0

Do the [Optional], [In] and [Out] attributes ever affect the behavior of a C# program?

    static void F([Optional]string s, [In] int i, [Out] int i2)
    {
    }

The attributes appear to do nothing at the C# language level. Is that true in all cases? Is there any relationship to out and ref parameters?

This question is out of curiosity only. I just found a tool bug where a tool erroneously treated [Out] like out.

boot4life
  • 4,966
  • 7
  • 25
  • 47
  • more info: http://stackoverflow.com/questions/5252389/difference-in-the-behavior-of-optionalattribute-used-to-declare-an-optional-par – DLeh Apr 18 '16 at 17:12
  • If don't follow what you mean by [Out] like out but it appears you have an answer that seems to understand the question. – paparazzo Apr 18 '16 at 17:22

1 Answers1

2

Mainly they affect interop behavior when using P/Invoke or COM.

For purely managed, non COM, code I don't think there is any other behavior changes in the stock .NET libraries.

Scott Chamberlain
  • 124,994
  • 33
  • 282
  • 431