What's the difference between [Out] and out in C#? [duplicate]

橙三吉。 提交于 2019-12-12 13:35:24

问题


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


回答1:


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#.




回答2:


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



来源:https://stackoverflow.com/questions/16835906/whats-the-difference-between-out-and-out-in-c

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!