Time of Update: 2018-12-08
複製代碼 代碼如下:using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;using System.IO;using System.Xml;using
Time of Update: 2018-12-08
一、普通Singleton複製代碼 代碼如下:#include<iostream>using namespace std;class Singleton{ public: static Singleton* getInstance(); private: static Singleton* instance; Singleton() { cout<<"constructor\n";
Time of Update: 2018-12-08
複製代碼 代碼如下:private void button1_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(this.textBox1.Text.Trim())) { MessageBox.Show("請輸入需要轉換的資訊!"); return; }
Time of Update: 2018-12-08
反射提供了封裝程式集、模組和類型的對象(Type 類型)。可以使用反射動態建立類型的執行個體,將類型綁定到現有對象,或從現有對象擷取類型並調用其方法或訪問其欄位和屬性。如果代碼中使用了屬性,可以利用反射對它們進行訪問。下面我就以一個案例來說明反射在項目中的使用方法。大體分為三個步驟:第一步,在web.config配置如下代碼(目的是為了動態去修改所需分析的dll)複製代碼 代碼如下:<appSettings> <add key="BizAssembly" value=
Time of Update: 2018-12-08
複製代碼 代碼如下: //路徑, 添加開機啟動/刪除開機啟動 public static void SetAutoRun(string fileName, bool isAutoRun) { RegistryKey reg = null; try { if (!System.IO.File.Exists(fileName))
Time of Update: 2018-12-08
複製代碼 代碼如下:/// <summary> /// 刪除掉空檔案夾 /// 所有沒有子“檔案系統”的都將被刪除 /// </summary> /// <param name="storagepath"></param> public static void KillEmptyDirectory(String storagepath) {
Time of Update: 2018-12-08
這裡使用Atrribute的方式實現了Json字串向C#對象的轉變。因為功能局限,此版本只是針對於Json字串,如"response":"Hello","id":21231513,"result":100,"msg":"OK."; 而不是Json數組。這裡的Atrribute是作用在屬性上,像NHibernate中的Atrribute一樣,是在運行時通過反射來擷取這個屬性對應於Json字串中的哪個key.複製代碼 代碼如下:namespace JsonMapper{
Time of Update: 2018-12-08
view plaincopy to clipboardprint?複製代碼 代碼如下://手動儲存圖片 private void saveBtn_Click(object sender, System.EventArgs e) { bool isSave = true; SaveFileDialog saveImageDialog = new SaveFileDialog();
Time of Update: 2018-12-08
通過觀察發現矩陣的下標有這樣一個規律:a行遞增後b列遞增然後c行遞減再d列遞減,但是對應值卻是逐漸增加的。因此可用4個迴圈實現,需要注意的是在賦值時不要把之前的值覆蓋了。所以在這裡選擇相同顔色部分賦值,代碼如下:複製代碼 代碼如下:#include <iostream>#include <iomanip>using namespace std;// 輸出螺旋矩陣void Matrix(){ const int size = 10; // 矩陣大小 int
Time of Update: 2018-12-08
1,建立預存程序複製代碼 代碼如下:create proc Pro_Login(@UserName nvarchar(10),@PassWord nvarchar(10))as select * from [User] UserName=@UserName and PassWord=@PassWord 2,通過類是實現設定資料庫字串串連複製代碼 代碼如下:class ConnectionString{public static string conStr = "Data
Time of Update: 2018-12-08
複製代碼 代碼如下:public static IPAddress GetHostIP(){ IPHostEntry ipe = Dns.GetHostEntry(Dns.GetHostName()); IPAddress ip = ipe.AddressList[0]; return ip;}private String GetIPAddress(){ String str;
Time of Update: 2018-12-08
複製代碼 代碼如下:#include<stdio.h>#include<windows.h>void FindFile(char* ,char* );int count=0;//統計檔案數char fname[32];#define BUFSIZE 256int main(int argc,char* argv[]){ char szLogicalDriveStrings[BUFSIZE]; DWORD iLength; int iSub;
Time of Update: 2018-12-08
最近在編寫C++程式的過程中,需要使用matlab產生的.mat檔案,於是尋找了基本使用方法。 我的電腦環境是win7 64位系統,VS2010,matlab R2010b。 一、工程配置: 1.VC++目錄->包含目錄 添加: MATLAB\R2010b\extern\include MATLAB\R2010b\extern\include\win64 ->庫目錄 添加: MATLAB\R2010b\extern\lib\win64\microsoft
Time of Update: 2018-12-08
複製代碼 代碼如下:using System;using System.Collections.Generic;using System.Linq;using System.Web;/// <summary>/// 防SQL注入檢查器/// </summary>public class SqlChecker{ //當前請求對象 private HttpRequest request; //當前響應對象 private HttpResponse
Time of Update: 2018-12-08
源碼:複製代碼 代碼如下:[StructLayout(LayoutKind.Explicit)] public struct IP { public IP(UInt32 value) { this._text1 = 0; this._text2 = 0; this._text3 = 0; this._text4 = 0; this._value = value; } public
Time of Update: 2018-12-08
1. foreach語句C#編譯器會把foreach語句轉換為IEnumerable介面的方法和屬性。複製代碼 代碼如下: foreach (Person p in persons) { Console.WriteLine(p); }foreach語句會解析為下面的程式碼片段。•調用GetEnumerator()方法,獲得數組的一個枚舉•在while迴圈中,只要MoveNext()返回true,就一直迴圈下去•用Current屬性訪問數組中的元素複製代碼 代碼如下: IEnumerator
Time of Update: 2018-12-08
•靜態建構函式既沒有存取修飾詞,也沒有參數。•如果沒有編寫靜態建構函式,而這時類中包含帶有初始值設定的靜態欄位,那麼編譯器會自動產生預設的靜態建構函式。•在建立第一個類執行個體或任何靜態成員被引用時,.NET將自動調用靜態建構函式來初始化類,也就是說我們無法直接調用靜態建構函式,也就無法控制什麼時候執行靜態建構函式了。•如果類中包含用來開始執行的 Main 方法,則該類的靜態建構函式將在調用 Main 方法之前執行。•如果類中的靜態欄位帶有初始化,則靜態欄位的初始化語句將在靜態建構函式之前運行。
Time of Update: 2018-12-08
GB2312是簡體中文系統的標準編碼 用“區” 跟“位”的概念表示 稱之為區位碼 區指代大的範圍 位相當於位移量。每個漢字佔兩個位元組高位位元組”的範圍是0xB0-0xF7,“低位位元組”的範圍是0xA1-0xFE。它的規律好像是按拼音a到z的順序排列的“啊”字是GB2312之中的第一個漢字,它的區位碼就是1601為此我們現在用代碼的方式輸出一個漢字c#下是little位元組序 b0跑後面去了。複製代碼 代碼如下: ushort u = 0xa1b0; byte[] chs
Time of Update: 2018-12-08
複製代碼 代碼如下:usingSystem; usingSystem.Collections.Generic; usingSystem.Linq; usingSystem.Text; usingSystem.Drawing; usingSystem.IO; namespaceMicrosoft.Form.Base { classImageToByte { /// <summary> /// 圖片轉換成位元組流 /// &
Time of Update: 2018-12-08
複製代碼 代碼如下:string t = DateTime.Now.Ticks.ToString(); t = DESKey.DESEncrypt(t, DESKey.DesKeyStr); string[] strid = new string[t.Length];// for (int i = 0; i < t.Length; i++)//把字元賦給數組 {