C Sharp
跳至導覽
跳至搜尋
C#,參照:『維基百科~C_Sharp_(programming_language)』
技術文件
- C# 文件 - 入門、教學課程、參考。 | Microsoft Docs
- GitHub - dotnet/csharpstandard: Working space for ECMA-TC49-TG2, the C# standard committee.
- 其它
- 參照:『維基百科~C_Sharp_syntax』
- 參照:『維基教科書~Category:Shelf:C_Sharp_programming_language』
- pinvoke.net: the interop wiki! (在C#中使用Win32 API的各函數定義方式)
- Code Review Checklist & Guidelines for C# Developers
- .NET and C# Versions - 20th Anniversary ♥ – nietras – Programming, mechanical sympathy, machine learning and .NET ❤.
版本
版本 | 語言規格 | 日期 | .Net版本 | Visual Studio版本 | ||
---|---|---|---|---|---|---|
ECMA | ISO/IEC | Microsoft | ||||
C# 1.0 | 2002年12月 | 2003年四月 | 2002年1月 | 2002年1月 | .NET Framework 1.0 | Visual Studio .NET 2002 |
C# 1.2 | 2003年10月 | 2003年4月 | .NET Framework 1.1 | Visual Studio .NET 2003 | ||
C# 2.0 | 2006年6月 | 2006年9月 | 2005年9月 | 2005年11月 | .NET Framework 2.0 .NET Framework 3.0 |
Visual Studio 2005 |
C# 3.0 | 否 | 2007年8月 | 2006年11月 | .NET Framework 2.0 (Except LINQ) .NET Framework 3.0 (Except LINQ) .NET Framework 3.5 |
Visual Studio 2008 | |
C# 4.0 | 2010年4月 | .NET Framework 4 | Visual Studio 2010 | |||
C# 5.0 | 2017年12月 | 2018年12月 | 2013年6月 | 2012年8月 | .NET Framework 4.5 | Visual Studio 2012/2013 |
C# 6.0 | 否 | C# 6.0 草稿規格 | 2015年7月 | .NET Framework 4.6 .NET Core 1.0 .NET Core 1.1 |
Visual Studio 2015 | |
C# 7.0 | Specification proposal | 2017年3月 | .NET Framework 4.7 | Visual Studio 2017 | ||
C# 7.1 | Specification proposal | 2017年8月 | .NET Core 2.0 | Visual Studio 2017 (Ver 15.3) | ||
C# 7.2 | Specification proposal | 2017年11月 | Visual Studio 2017 (Ver 15.5) | |||
C# 7.3 | Specification proposal | 2018年5月 | .NET Core 2.1 .NET Core 2.2 .NET Framework 4.8 |
Visual Studio 2017 (Ver 15.7) | ||
C# 8.0 | Specification proposal | 2019年9月 | .NET Core 3.0 .NET Core 3.1 |
Visual Studio 2019 (Ver 16.3) | ||
C# 9.0 | Specification proposal | 2019年9月 | .NET 5.0 | Visual Studio 2019 (Ver 16.8) | ||
C# 10.0 | Specification proposal | 2021年11月 | .NET 6.0 .NET 6.0.1 |
Visual Studio 2022 (Ver 17.0) |
相關工具
FAQ
跨語言整合
- JavaScript
- Javascript .NET
- Jurassic is an implementation of the ECMAScript language and runtime.
- ClearScript - supports JavaScript (via V8 and JScript) and VBScript.
- Jint - Javascript Interpreter for .NET
- Jint - (舊版專案)
C#之謎(數字後的m)
- 2 / 1000 等於 0 (輸出成Int32,因為變成整數除整數?)
- 2 / 1000m 等於 0.002 (輸出成Decimal)
自訂控制項的DataBinding
GC(記憶體回收)
System.GC.Collect();
使用VB.Net的物件或函數在C#
- 在C#之中使用VB.Net的 Left()、Mid()、Right()……等字串函數。
- 專案設定中,把 Microsoft.VisualBasic 加入參考。
- using Microsoft.VisualBasic;
- 把 Left() 改成 Strings.Left() 來用。
- 需注意在C#中,字串的字元索引是從0開始算的,而VB.NET是從1開始算的。
- 在C#之中使用VB.Net的 My 的命名空間。
Lambda 運算式
WebBrowser
- 需要先 using System.Net; 才能用
- 只對超連結有效,對於使用JavaScript去做window.open的無效
關於enum
- 判斷字串是否為enum裡定義過的
- 字串轉enum
- System.Enum.Parse
- System.Enum.TryParse(.Net Framework 4.0以後才有)
- 或是
//版本1 private bool TryParseEnum<T>(string valueToParse, out T returnValue) { if (Enum.IsDefined(typeof(T), valueToParse)) { returnValue = (T)Enum.Parse(typeof(T), valueToParse); return true; } returnValue = default(T); return false; } //版本2 (需要 using System.ComponentModel; ) private bool TryParseEnum<T>(string valueToParse, out T returnValue) { if (Enum.IsDefined(typeof(T), valueToParse)) { TypeConverter converter = TypeDescriptor.GetConverter(typeof(T)); returnValue = (T)converter.ConvertFromString(valueToParse); return true; } returnValue = default(T); return false; }
執行外部執行檔
遠端檔案下載
- 透過 System.Net.WebClient 從遠端的 Web-Server 下載檔案。
using System.Net; Uri UriSrc = new Uri(strSrcUrl); // Create a new WebClient instance. using (WebClient objWebClient = new WebClient()) { if (IsAsync == true) objWebClient.DownloadFileAsync(UriSrc, strFilename); else objWebClient.DownloadFile(UriSrc, strFilename); }
取得目前執行檔的檔名與路徑
using System; using System.Diagnostics; [DllImport("user32.dll")] private static extern IntPtr GetWindowThreadProcessId(IntPtr hWnd, IntPtr ProcessId); private string GetCurrentProcessFileName() { return Process.GetCurrentProcess().MainModule.FileName; } private string GetWindowModuleFileName(IntPtr hwnd) { uint pid = 0; GetWindowThreadProcessId(hwnd, out pid); return Process.GetProcessById((int)pid).MainModule.FileName; }
宣告結構陣列
C#的特殊應用
- 驅動程式
- EFI
標準資料流
- Console 類別 (System) | Microsoft Docs
- Process.StandardInput 屬性 (System.Diagnostics) | Microsoft Docs
- Process.StandardOutput 屬性 (System.Diagnostics) | Microsoft Docs*
- Process.StandardError 屬性 (System.Diagnostics) | Microsoft Docs