發表文章

目前顯示的是 5月, 2019的文章

[LeetCode] Exchange Seats

   SELECT m . id         , IFNULL ( IF ( ( m . id & 0x1 ) = 1 , r1 . student , r2 . student ), m . student ) AS 'Student'      FROM seat m LEFT JOIN seat r1        ON r1 . id = ( m . id + 1 ) LEFT JOIN seat r2        ON r2 . id = ( m . id - 1 )     ORDER BY id Runtime :  166 ms , faster than  58.92%  of MySQL online submissions for Exchange Seats. ------------------------------------------------------------------------ 似乎不好,但簡單的寫法,歡迎大家流言討論,讓你我更好。

[LeetCode] Robot Return to Origin

  public class Solution {       public bool JudgeCircle( string moves)       {           var ms = moves.ToArray();           int Y = ms.Count(c => c == 'U' ) - ms.Count(c => c == 'D' );           int X = ms.Count(c => c == 'L' ) - ms.Count(c => c == 'R' );           return X == 0 && Y == 0;       } } Runtime:  108 ms , faster than  9.14%  of C# online submissions for Robot Return to Origin. Memory Usage:  25.8 MB , less than  5.55%  of C# online submissions for Robot Return to Origin. -------------------------------------------------------------------------------------------- 似乎不好,但簡單的寫法,歡迎大家流言討論,讓你我更好。

C# DB數字型態 對應

             [SQL] ------------------------------------ bigint   | -2^63~2^63-1)| 8位元組 ------------------------------------ int      |(-2^31~2^31-1)| 4位元組 ------------------------------------ smallint |(-2^15~2^15-1)| 2位元組 ------------------------------------ tinyint  |(0~255)       | 1位元組              [.netC#] ------------------------------------ Int64    | -2^63~2^63-1)| 8位元組 ------------------------------------ Int32    |(-2^31~2^31-1)| 4位元組 ------------------------------------ Integer  |(-2^31~2^31-1)| 4位元組 ------------------------------------ Int16    |(-2^15~2^15-1)| 2位元組 ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓對應↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ [MS SQL] [C#] bit      <=> bool tinyint      <=> byte smal...

C# Stream 轉 Bytes

        #region - Stream 轉 Bytes -         /// <summary>         /// Stream 轉 Bytes         /// </summary>         /// <param name="stream"> Stream </param>         /// <returns> Bytes </returns>         public static byte [] StreamToBytes( Stream stream)         {             byte [] bytes = new byte [stream.Length];             stream.Read(bytes, 0, bytes.Length);             stream.Seek(0, SeekOrigin .Begin);             return...

MS SQL 目的:用浮點數加減時間換算

目的:用浮點數加減時間換算,例如:日期時間加上0.5小時 SELECT DATEADD(HOUR, 0.5, CAST('2015/01/01 08:00' AS DATETIME)) 執行結果還是一樣 2015/01/01 08:00 SELECT DATEADD(MINUTE, 0.5 * 60, CAST('2015/01/01 08:00' AS DATETIME)) 執行結果 2015/01/01 08:30 原因: DATEADD (datepart , number , date ) 參數:number,主要為int型別,0.5轉換int還是0 參考網址 https://msdn.microsoft.com/zh-tw/library/ms186819.aspx

C# 下載檔案 - [檔名亂碼問題]

http://www.dotblogs.com.tw/siro228/archive/2008/10/13/5665.aspx context.Response.ContentType = "application/octet-stream" ; string filename = HttpUtility.UrlPathEncode( "中文檔名.ppt" ); context.Response.AddHeader( "content-disposition" , "attachment; filename=\"" + filename + "\";" ); byte [] data = ( byte [])dt.Rows[0][ "Data" ]; context.Response.AddHeader( "Content-Length" , data.Length.ToString()); context.Response.BinaryWrite(data); context.Response.End(); 由於FireFox不會發生,可加上下面的code避開(請參考資料來源) if (Request.Browser.Browser == "IE" ) { fileName = Server.UrlPathEncode(fileName); }

C# 檔案對應fiel Content Tyoe

http://www.dotblogs.com.tw/larrynung/archive/2011/03/24/22049.aspx private static string GetContentTypeForFileName(string fileName)  {      string ext = System.IO.Path.GetExtension(fileName);      using (Microsoft.Win32.RegistryKey registryKey = Microsoft.Win32.Registry.ClassesRoot.OpenSubKey(ext))      {          if (registryKey == null)              return null;          var value = registryKey.GetValue("Content Type");          return (value == null) ? string.Empty : value.ToString();      }  }  完整範例如下: using System;  using System.Collections.Generic;  using System.Linq;  using System.Text;  namespace ConsoleApplication10  { ...

C# 圖片轉換格式(附檔名)

http://www.iteddie.com/2010/11/c_15.html /// 要儲存的圖片 /// 品質(0~100) /// 儲存路徑 private void SaveAsJPEG( Image img, int qulity, string path) { EncoderParameters myEncoderParameters = new EncoderParameters(1); EncoderParameter myEncoderParameter = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, qulity); myEncoderParameters.Param[0] = myEncoderParameter; img.Save(path, GetEncoder(ImageFormat.Jpeg), myEncoderParameters); } /// /// 取得已安裝的影像 Codec 的相關資訊 /// /// System.Drawing.Imaging.ImageFormat /// System.Drawing.Imaging.ImageCodeInfo private ImageCodecInfo GetEncoder(ImageFormat format) {      ImageCodecInfo[] codecs = ImageCodecInfo.GetImageDecoders();      foreach (ImageCodecInfo codec in codecs)      {           if (codec.FormatID == format.Guid)           {   ...

C# 在 GDI+ 中發生泛型錯誤

http://blog.miniasp.com/post/2009/05/A-generic-error-occurred-in-GDI-plus.aspx 解決: 1. http://stackoverflow.com/questions/15571022/how-to-find-reason-for-generic-gdi-error-when-saving-an-image (會造成 記憶體不足) ----------------------------------------------------------------------------------------------------- 2.使用暫存檔及壓縮jpg層級等級                      var tempFilePath = Path .Combine(strSavePath,rows + ".tmp" );                     file.SaveAs(tempFilePath);                     using ( var result = new Bitmap (tempFilePath))                     {             ...

C# 刪除路徑中資料夾及檔案

             string strSavePath = Server.MapPath( "~/Temp/" );             string [] files = Directory .GetFiles(strSavePath);//中的檔案             string [] dirs = Directory .GetDirectories(strSavePath);//中的目錄             foreach ( string file in files)             {                 System.IO. File .SetAttributes(file, FileAttributes .Normal);                 System.IO. File .Delete(file);             }             foreach ( string dir in dirs)...

C# 確認國籍身分證

        #region - 確認國籍身分證 -         /// <summary>         /// 確認國籍身分證         /// </summary>         /// <param name="country"> 國別代碼 </param>         /// <param name="idno"> 身分證字號 </param>         /// <returns></returns>         public static bool GetCheckIdno( EnumCountry country, string idno)         {             switch (country)             {                 case EnumCountry .TW:     ...

C# 檢查DPI

System.Drawing.Image img = System.Drawing.Image.FromFile (fileName); //获取此图形的水平分辨率(即水平dpi)(以像素/英寸为单位) float dpiX = img.HorizontalResolution ; //垂直分辨率 float dpiY = img.VerticalResolution;