跳到主要內容

發表文章

目前顯示的是 3月, 2016的文章

[C#]將特定字串或數值轉成列舉成員

根據微軟的官方文件記載 Enum.Parse 方法可以將列舉常數的名稱或數值傳換成相等的列舉物件(Sample code 如下所式) Converts the string representation of the name or numeric value of one or more enumerated constants to an equivalent enumerated object. enum   ExitCodes   :   int {   Success = 0,   SignToolNotInPath = 1,   AssemblyDirectoryBad = 2,   PFXFilePathBad = 4,   PasswordMissing = 8,   SignFailed = 16,   UnknownError = 32 } Sample code : int   code =0; ExitCodes   value = ( ExitCodes   ) Enum .Parse( typeof   ( ExitCodes   ), code.ToString());      System. Console .WriteLine( value   .ToString()); Output: Success

[C#] 取得 enum 裡的成員個數

Total number of items defined in an enum Way1   int  number= Enum .GetNames( typeof ( MYEnum )).Count(); Way2 public enum MYEnum{           Dog,           Pig,           Cat,           NumberOfMyEnum } static void Main(string[] args)   {           int number=(int)MYEnum. NumberOfMyEnum   }

[C++] 使用iterator型別走訪 list 集合

使用 iterator 型別來走訪 list  lstINFHWIDs 集合裡的元素 list < CString >:: iterator iteINFHWIDs ;   for ( iteINFHWIDs = lstINFHWIDs . begin () ; iteINFHWIDs != lstINFHWIDs . end () ; iteINFHWIDs ++)   {      CString strMapKey = (* iteINFHWIDs ). MakeUpper ();      //implement ...

[C#] 如何讀取Excel 中的某個欄位

如果想從這份xls檔案裡取出Wild這本書的價格(Price) 1. 需要 -add reference NPOI.dll -   匯入NPOI.HSSF.UserModel , NPOI.SS.UserModel; using   NPOI.HSSF.UserModel; using   NPOI.SS.UserModel; 2. 開檔(假設檔案路徑是  C:\book1.xls  ) HSSFWorkbook   wookbook; string  filepath=@"C:\book1.xls"; FileStream   file =   new   FileStream   ( filepath ,   FileMode .Open,   FileAccess .Read); byte [] bytes =   new   byte [file.Length]; file.Read(bytes, 0, (   int )file.Length); MemoryStream   ms =   new   MemoryStream   (bytes); wookbook =   new   HSSFWorkbook (ms); 3. 以每一行(row)的第一個欄位來做搜索匹配   public     string   GetToolConfigCell( HSSFWorkbook   wookbook   , string   sheetName,   string   rowName,   string   columnName)    {               ISheet   sheet = wookbook.GetSheet(sheetName);               if   (sheet ==   null )                   return   null ;               int   rowIndex = -1;               int   col