2015-08-28 43 views
0

C#默认平台调用对方法参数和结构字段字符串使用ANSI编组。“DefaultCharSetAttribute”是否也适用于“StructLayoutAttribute.CharSet”?

System.Runtime.InteropServices包含一个属性“DefaultCharset”以将其更改为Unicode。

从MSDN:“在程序集级别或模块级别应用DefaultCharSetAttribute属性,为任何不包含用户指定的CharSet命名参数的DllImportAttribute调用设置CharSet值。

我的问题是:该属性是否也设置了“StructLayoutAttribute.CharSet”的默认值?

谢谢!

回答

1

试试看:

using System; 
using System.Runtime.InteropServices; 

[module: DefaultCharSet(CharSet.Unicode)] 

class Program { 
    static void Main(string[] args) { 
     var sla = typeof(Foo).StructLayoutAttribute; 
     Console.WriteLine(sla.CharSet); 
     Console.ReadLine(); 
    } 
} 

struct Foo { }; 

输出:

Unicode 

所以,是的。

相关问题