c# - 在方法中使用 [in, out]

标签 c# com-interop

<分区>

我想问一下有什么区别

public int Method1([In, Out] byte[] buffer);

public int Method2(byte[] buffer);

我遇到了 http://referencesource.microsoft.com/#mscorlib/system/io/stream.cs,739想知道为什么 [In, Out] 在那里?

最佳答案

是的。有区别。

  • public int Method2(byte[] buffer); 使用隐式 In :

    Indicates that data should be marshaled from the caller to the callee, but not back to the caller.

  • public int Method2(out byte[] buffer); 使用 Out :

    Indicates that data should be marshaled from callee back to caller.

  • public int Method2(ref byte[] buffer); 使用 [In, Out]

关于c# - 在方法中使用 [in, out],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39393949/

相关文章:

c# - W10 UWP - 将远程图像设置为桌面墙纸/锁屏

c# - 如何为 Mesh3D 正确设置纹理坐标

c# - C# 中的非托管句柄,我需要释放还是销毁?

c# - C# 结构的属性在 COM 和 VB6 中获得不可用的名称?

c# - 将 NULL 传递给 COM 接口(interface)方法的 ref/out 参数

c# - 最佳实践 : How to expose a read-only ICollection

c# - 使用来自 .NET 命令行应用程序的签名 Google Maps API 地理编码请求

c# - 当类的名称是根元素时,Newtonsoft json 不会反序列化

c# - 从 COM 调用托管 API

c# - 在 .NET 中将属性公开为变体以进行互操作