1: using System; 2: using System.Collections.Generic; 3: using System.Linq; 4: using System.Windows.Forms; 5: using System.Threading; 6: 7: namespace MutexSample 8: { 9: static class Program 10: { 11: ///
/// <summary> /// /// loads a *.dll file from txtMethods and invokes all methods int it. /// lists all types in the assembly /// /// </summary> /// <param name="sender"></param> /// <param
前些日子做一個Web項目,必須自己編寫一個ActiveX控制項。如今的ActiveX控制項大多是使用VB/C++來開發的,而我對他們並不熟悉,因此考慮使用熟悉的C#編寫ActiveX控制項。 首先,建立一個WinForm控制項項目HelloWorld,並拖入一個Label控制項,文字設為HelloWorld, UserControl1.cs內容如下: using System; using System.Collections;
嘗試了一下用C#寫了一下二叉樹的相關演算法: 代碼Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--> #region 擷取二叉樹深度 static int z, d = 0; //z用於記錄遍曆到某節點時的深度,d用於記錄最大深度 static int GetTreeDep(TreeNode node)
調用建構函式和解構函式的順序先構造的後析構,後構造的先析構。歸納下什麼時候調用建構函式和解構函式(1) 全域範圍內定義的對象,他的建構函式在檔案中所有函數執行之前執行。但是當程式定義了多個檔案,而不同的檔案中都定義全域變數時候,,則對象的建構函式的調用順序是不確定的,當main函數結束或者運行了exit函數時,調用解構函式(2) 定義的是局部自動對象時,則在建立對象是調用其建構函式。如果函數多次調用,則在每次建立對象是後都要調用建構函式,函數調用結束時調用解構函式(3) Sta
任務結束時,它可以把一些有用的狀態資訊寫到共用對象中。這個共用對象必須是安全執行緒的。另一個選項是使用返回某個結果的任務。使用Task類的泛型版本,就可以定義返回某個結果的任務的傳回型別。為了返回某個結果任務調用的方法可以聲明為帶任意傳回型別。樣本方法TaskWithResult()利用一個元組返回兩個int值。該方法的輸入可以是void或object類型,如下所示: 1: using System; 2: using System.Collections.Generic; 3:
1: using System; 2: using System.Collections.Generic; 3: using System.Linq; 4: using System.Text; 5: using System.Threading; 6: using System.Threading.Tasks; 7: 8: namespace SynchronizationSamples 9: { 10: public class
1: using System; 2: using System.Collections.Generic; 3: using System.Linq; 4: using System.Text; 5: using System.Threading; 6: using System.Threading.Tasks; 7: 8: namespace SynchronizationSamples 9: { 10: public class
1: using System; 2: using System.Collections.Generic; 3: using System.Linq; 4: using System.Text; 5: using System.Threading; 6: using System.Diagnostics; 7: 8: namespace Semaphore 9: { 10: class Program 11: { 12: