Time of Update: 2018-12-08
複製代碼 代碼如下:// this.SizeChanged += new System.EventHandler(this.Form1_SizeChanged); //上面一行是主表單InitializeComponent()方法中需要添加的引用 private void Form1_SizeChanged(object sender, EventArgs e) { if (this.WindowState==FormWindowState.Minimized) { this.Hide();
Time of Update: 2018-12-08
本文主要記錄的是C#各種集合操作的效能,下面的標記說明描述標記的時間,下面的表格對比各種集合各種操作的時間. 標記說明: 1.O(1) 表示無論集合中有多少項,這個操作需要的時間都不變,例如,ArraryLIst的Add()方法就O(1), 無論集合中有多少元素,在列表尾部添加一個新的元素的時間都是相同的. 2. O(n)表示對於集合中的每個元素,需要增加的時間量都是相同的,如果需要重新給集合分
Time of Update: 2018-12-08
1. 採用CustomSource當做提示集合 將下列代碼添加到視窗載入函數中即可。假設unitNameList是擷取的想要添加到下拉式清單中的字串列表。 複製代碼 代碼如下:AutoCompleteStringCollection collection = new AutoCompleteStringCollection(); // 擷取單位列表 List<string> unitNameList = this.getAllUnitName(); foreach (string
Time of Update: 2018-12-08
今天同學遇到一個在C語言中全域數組和局部數組的問題,卡了許久,我也沒有第一時間看出問題,現在把問題梳理一下,並給出解決方案。 問題描述: 在全域聲明的數組與在局部聲明的數組有著不同的效果。 首先來看一個程式: 複製代碼 代碼如下:#include <stdio.h> #include <stdlib.h> #define MAX 10 char a[MAX]; int main() { int i; char b[MAX]; char *c=(char *)malloc(
Time of Update: 2018-12-08
如果某個衍生類別的部分或者全部直接基類是從另一個共同的基類派生而來,在這些俄直接基類中, 從上一級基類繼承來的成員就擁有相同的名稱,因此衍生類別中就會出現同名現象。對這種類型的同名成員也要使用範圍分辨符來唯一標識,而且必須使用直接基類來進行限定。 -------------------------------------------------- /* * File: main.cpp * Author: yubao * * Created on May 31, 2009, 8:54 AM */
Time of Update: 2018-12-08
重新指定分配預設值的參數時,可以顯式地為指定參數名稱賦值,隱式指定的時候,是根據方法參數的順序,靠c#編譯器的推斷。 程式碼範例: 複製代碼 代碼如下:void M(int x=9,string s="a",DateTime dt = default(DateTime)) {...} Main() { M();//使用預設值 M(8,"b")://隱式指定方法參數,沒有指定的使用預設值 M(6,"v",DateTime.Now);//同上
Time of Update: 2018-12-08
複製代碼 代碼如下:using System; using System.Text; namespace StringLengthTest { class Program { static void Main(string[] args) { string strTmp = "abcd1234軟體包"; int i = Encoding.GetEncoding("GB2312").GetBytes(strTmp).Length; int j =
Time of Update: 2018-12-08
要使用SAPI,首先添加引用DotNetSpeech,請自行下載DotNetSpeech.dll。 初始化對象,SpVoice voice = new DotNetSpeech.SpVoiceClass(); 朗讀時,使用 voice.Speak(string,SpeechVoiceSpeakFlags.SVSFlagsAsync); 暫停,使用 voice.Pause(); 從暫停中繼續剛才的朗讀,使用 voice.Resume();
Time of Update: 2018-12-08
複製代碼 代碼如下:/* * 使用 C# 動態編譯代碼和執行 * 作者: yaob */ static void Main(string[] args) { // 編譯器 CodeDomProvider cdp = CodeDomProvider.CreateProvider("C#"); // 編譯器的參數 CompilerParameters cp = new CompilerParameters(); cp.ReferencedAssemblies.Add("System.dll");
Time of Update: 2018-12-08
複製代碼 代碼如下:$.request = (function () { var apiMap = {}; function request(queryStr) { var api = {}; if (apiMap[queryStr]) { return apiMap[queryStr]; } api.queryString = (function () { var urlParams = {}; var e, d = function (s) { return
Time of Update: 2018-12-08
一、基本概念 堆:這裡是指一種資料結構,而不是我們在C#中提到的用於儲存參考型別對象的地方。它可以被當成一棵完全二叉樹。 為了將堆用數組來存放,這裡對每個節點標上順序。事實上,我們可以用簡單的計算公式得出父節點,左孩子,右孩子的索引: parent(i) = left(i) = 2i right(i)=2i + 1最大堆和最小堆: 最大堆是指所有父節點的值都大於其孩子節點的堆,即滿足以下公式:
Time of Update: 2018-12-08
在方法聲明中只允許一個paras關鍵字,並且該關鍵字只能為最後一個。複製代碼 代碼如下:using System; /****************************** * Chapter:C#痛點逐個擊破(三) * Author:王洪劍 * Date:2010-1-16 * Blog:http://www.51obj.cn/ * Email:walkingp@126.com * Description:數組參數params的使用 * *************************
Time of Update: 2018-12-08
一般情況,方法的參數傳遞是通過值進行傳遞的,即一個對象作為參數傳遞給方法使用,該對象便進駐到該參數對象所在指標的記憶體空間(使用C來描述),也就是該對象在此位置建立了副本,當方法運行結束時,該副本將會被銷毀;這種傳遞方式的使用佔據了日常方法傳參的絕大多數。另一種情況是引用傳遞,它與值傳遞方式不同,對象傳遞給方法時對方法參數並沒有影響,仍然返回的是受原始參數取值影響的方法,即MethodInstance(ref _refValue)調用 Method(ref
Time of Update: 2018-12-08
CREATE PROC P_TEST@Name VARCHAR(20), @Rowcount INT OUTPUT AS BEGIN SELECT * FROM T_Customer WHERE NAME=@Name SET @Rowcount=@@ROWCOUNT END GO ---------------------------------------------------------------------------------------- --預存程序調用如下: --------
Time of Update: 2018-12-08
當前選中項:TreeView.SelectedNode 增加頂級節點:TreeView.Nodes.Add("Key", "Text") 增加同級節點:TreeView.SelectedNode.Parent.Nodes.Add("Key", "Text") 增加子節點:TreeView.SelectedNode.Nodes.Add("Key", "Text") 全部展開:TreeView.ExpandAll() 全部收攏:TreeView.CollapseAll() 重新設定TreeView
Time of Update: 2018-12-08
複製代碼 代碼如下:XmlDocument downLoadFilexml = new XmlDocument(); XmlElement root = null; XmlElement kisokChild = null; //產生xml的頭 XmlNode xmlnode= downLoadFilexml.CreateXmlDeclaration("1.0", "utf-8", null); downLoadFilexml.AppendChild(xmlnode); root =
Time of Update: 2018-12-08
1、DateTime 數字型 System.DateTime currentTime=new System.DateTime(); 1.1 取當前年月日時分秒 currentTime=System.DateTime.Now; 1.2 取當前年 int 年=currentTime.Year; 1.3 取當前月 int 月=currentTime.Month; 1.4 取當前日 int 日=currentTime.Day; 1.5 取當前時 int 時=currentTime.Hour; 1.6
Time of Update: 2018-12-08
需要添加對 System.Management.dll 的引用 複製代碼 代碼如下:using System.Diagnostics; using System.Management;static void Main(string[] args) { foreach (Process p in Process.GetProcesses()) { Console.Write(p.ProcessName); Console.Write("----");
Time of Update: 2018-12-08
C#中通過Assembly類可以訪問程式集資訊. 1.允許訪問給定程式集的元元素,包含可以載入和執行程式集的方法; 2.載入程式集:使用靜態方法Assembly.Load(程式集名稱)或Assembly.LoadFrom(程式集完整路徑名); 3.屬性: FullName:程式集顯示名稱; 3.方法: GetTypes():擷取程式集中定義的類型。 TestAssembly.cs: view plaincopy to clipboardprint? using System; using
Time of Update: 2018-12-08
在程式的main函數中加入以下代碼 bool createdNew; System.Threading.Mutex instance = new System.Threading.Mutex(true, "MutexName", out createdNew); if (createdNew) { Application.Run(new LoginForm()); instance.ReleaseMutex(); } else { Application.Exit(); } 還可以寫成以下形式,