3C科技 娛樂遊戲 美食旅遊 時尚美妝 親子育兒 生活休閒 金融理財 健康運動 寰宇綜合

Zi 字媒體

2017-07-25T20:27:27+00:00
加入好友
C#的結構(struct)中使用陣列(array) 對應 C++的結構(struct) 資料來源:http://codingjames.blogspot.tw/2009/08/cstructarray.html   C#是物件導向的語言,所以並不建議在其中使用結構 需要使用的時候最好儘量使用類別(class)來取代 不過有時候還是會需要定義結構,比如使用前人定義出的結構時 為了要和非.net(unmanagement)的程式庫(dll)溝通 還是需要定義出符合原本定義的結構,如果都只用到一些共通的形態的話 那在C#和C++中的定義基本上是一樣的 以下的範例(版主實際應用): C#:     public struct CardInfo     {         public int intType;//卡片類型         public int intUsage;//卡片用途         public int intConfiguration;//延伸資料類型         public int intPassThroughCounter;//通行次數         public int intHolidayWeekProgramValue;//周計畫+假日通行設定         public int intStartExpirationDate;//卡片有效期限設定         public int intEnd1eExpirationDate;//卡片有效期限設定         [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 17)]         public string strStartExpirationDate;//’YYYYMMddHHmm’         [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 17)]         public string strEndleExpirationDate;//’YYYYMMddHHmm’         public int intFirstPassThroughTimeRange;//可通行時段         public int intSecondPassThroughTimeRange;//可通行時段         public int intThirdPassThroughTimeRange;//可通行時段         [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 17)]         public string strUserUniqueIdentifier;//用戶識別碼 “AAAAAAAA”(PS長度和原本不同)         [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 5)]         public string strScramblerCode;//擾碼設定 “aaaa”(PS長度和原本不同)         //———————————————————–         //延伸資料         [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 9)]         public string strUserPasswordCode;//使用者密碼設定 “12345678”(單一個)         [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 9)]         public string strDoorName1;//門區名稱設定(使用類似ArrayList方式存取) GWC_DOOR_NAME_LENGTH_MAXIMUM=8         [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 9)]         public string strDoorName2;//門區名稱設定(使用類似ArrayList方式存取) GWC_DOOR_NAME_LENGTH_MAXIMUM=8         [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 9)]         public string strDoorName3;//門區名稱設定(使用類似ArrayList方式存取) GWC_DOOR_NAME_LENGTH_MAXIMUM=8         public int intDoorNameSize;//紀錄SIZE         [MarshalAs(UnmanagedType.ByValArray, SizeConst = 1152)]//http://codingjames.blogspot.tw/2009/08/cstructarray.html         public int []intDoorAccess;//new int[1152];//門區群組設定(使用類似ArrayList方式存取) MAX=1152         public int intDoorAccessSize;//紀錄SIZE     } C++:     typedef struct _CardInfo     {         int intType;//卡片類型         int intUsage;//卡片用途         int intConfiguration;//延伸資料類型         int intPassThroughCounter;//通行次數         int intHolidayWeekProgramValue;//周計畫+假日通行設定         int intStartExpirationDate;//卡片有效期限設定         int intEnd1eExpirationDate;//卡片有效期限設定         char strStartExpirationDate[17];//’YYYYMMddHHmm’         char strEndleExpirationDate[17];//’YYYYMMddHHmm’         int intFirstPassThroughTimeRange;//可通行時段         int intSecondPassThroughTimeRange;//可通行時段         int intThirdPassThroughTimeRange;//可通行時段         char strUserUniqueIdentifier[17];//用戶識別碼 “AAAAAAAA”(PS長度和原本不同)         char strScramblerCode[5];//擾碼設定 “aaaa”(PS長度和原本不同)         //———————————————————–         //延伸資料         char strUserPasswordCode[9];//使用者密碼設定 “12345678”(單一個)         char strDoorName1[9];//門區名稱設定(使用類似ArrayList方式存取) GWC_DOOR_NAME_LENGTH_MAXIMUM=8         char strDoorName2[9];//門區名稱設定(使用類似ArrayList方式存取) GWC_DOOR_NAME_LENGTH_MAXIMUM=8         char strDoorName3[9];//門區名稱設定(使用類似ArrayList方式存取) GWC_DOOR_NAME_LENGTH_MAXIMUM=8         int intDoorNameSize;//紀錄SIZE         int intDoorAccess[1152];//門區群組設定(使用類似ArrayList方式存取) MAX=1152         int intDoorAccessSize;//紀錄SIZE     }CardInfo;       

本文由jashliaoeuwordpress提供 原文連結

寫了 5860316篇文章,獲得 23313次喜歡
精彩推薦