原文:http://www.blogcn.com/user8/flier_lu/index.html?id=3318394
【相关文章:走进C#(我的C#学习之旅)序】【扩展阅读:几个比较好用的asp检查函数】
【扩展信息:匈牙利命名法】 在 c/c++ 代码中,大量掺杂着包括普通类型与数组的结构,如定义 pe 文件头结构的 image_optional_header 结构定义如下: 以下内容为程序代码: typedef struct _image_data_directory { dword virtualaddress; dword size; } image_data_directory, *pimage_data_directory; #define image_numberof_directory_entries 16 typedef struct _image_optional_header { word magic; //... dword numberofrvaandsizes; image_data_directory datadirectory[image_numberof_directory_entries]; } image_optional_header32, *pimage_optional_header32; 在 c/c++ 中这样在结构中使用数组是完全正确的,因为这些数组将作为整个结构的一部分,在对结构操作时直接访问结构所在内存块。但在 c# 这类语言中,则无法直接如此使用,因为数组是作为一种特殊的引用类型存在的,如定义: 以下内容为程序代码: public struct image_data_directory { public uint virtualaddress; public uint size; } public struct image_optional_header { public const int image_numberof_directory_entries = 16; public ushort magic; //... public uint numberofrvaandsizes; public image_data_directory datadirectory[image_numberof_directory_entries]; } 在 c# 中这样定义结构中的数组是错误的,会在编译时获得一个 cs0650 错误: 以下为引用: ... 下一页