Time of Update: 2017-02-28
函數|數組 執行個體:/// <summary>/// 使用者資訊結構/// </summary>public struct TUSER{ public string LoginName; public string LoginPass; public string TrueName; public string EMail; public int Level;}/// <summary>//
Time of Update: 2017-02-28
上一篇就結構的效能、局限性以及它和類的比較作了簡單的描述,這篇我將接著介紹在使用結構時應該注意和把握的原則: 通過上篇的介紹,我們可以很自然的意識到結構在效率上的優越性(相對於類),這主要歸因於它們在底層的實值型別結構。不過,它們的對於大容量資料和複雜度高的演算法進行處理時所表現出來的局限性,使得它的適用範圍大受限制。那我們在什麼情況下使用結構才能不受指責和嘲笑呢?
Time of Update: 2017-02-28
給圖片添加著作權資訊(C#) 現在越來越多的網站都喜歡將使用者上傳的圖片加上網站的著作權資訊,不要以為那是用photoshop之類的圖片處理軟體加上去的,其實我們只要寫一小段代碼,就可以實現這個功能。 添加著作權資訊的原理其實挺簡單:通過圖片擷取Graphics類的對象,該類有一個DrawString()方法可以將資訊寫到圖片上,甚至還可以做出各種各樣的效果,如浮水印,背景透明等。最後儲存圖片即大功告成了。
Time of Update: 2017-02-28
動態 (C#)利用反射動態調用類成員 使用反射動態調用類成員,需要Type類的一個方法:InvokeMember。對該方法的聲明如下(摘抄於MSDN):public object InvokeMember( string name, BindingFlags invokeAttr, Binder binder, object target, object[] args);參數name
Time of Update: 2017-02-28
Implementing the Singleton Pattern in C#view auther's websiteThe singleton pattern is one of the best-known patterns in software engineering. Essentially, a singleton is a class which only allows a single instance of itself to be created, and
Time of Update: 2017-02-28
public class QueueManage { /// /// 發送對象到隊列中 /// /// 隊列名稱,因為隊列名稱在一個應用中應該不改變的,所以大家最好寫在設定檔中 /// 要發出去的對象 public static void SendQueue(string QueuePath,MyBase.SmsQueue sq) { System.Messaging.MessageQueue mqSend=new
Time of Update: 2017-02-28
函數|區別 從vc入門編程的,相信大家都很熟悉PreTranslateMessage和WindowProc兩個函數,前者是預先處理windows發給控制項的訊息,後者是處理剩餘的控制項訊息。對於PreTranslateMessage函數,一般來說,我們是這樣處理控制項訊息的:BOOL test::PreTranslateMessage(MSG* pMsg) {if(pMsg->hwnd==GetSafeHwnd()){if(pMsg->
Time of Update: 2017-02-28
文字框 今天閑著無聊,試著用C#寫查看密碼框的程式(不僅限於密碼框,應該是任何有文本的控制項都可以)代碼見下面.用C++實現起來超簡單的這麼個東東..用C#複雜得很,我又不想用unsafe,我總覺得用unsafe的話,幹嘛不乾脆用C++算了.int Length=300;IntPtr THandle=APIs.GetLocalWindow();//取得當前滑鼠所在位置的控制項控制代碼int
Time of Update: 2017-02-28
//迷宮類相關using System;using System.Drawing;using System.Drawing.Drawing2D;using System.Collections;namespace MazeDemo{ /// <summary> /// 迷宮類 /// </summary> public class CMaze { bool[,] mg; //地圖格子 Stack stack; //堆棧 Point in_p; //進入點
Time of Update: 2017-02-28
//表單,調用...using System;using System.Drawing;using System.Collections;using System.ComponentModel;using System.Windows.Forms;using System.Data;using System.Threading;namespace MazeDemo{ /// <summary> /// Form1 的摘要說明。 /// </summary> public
Time of Update: 2017-02-28
現在關於oo的編程思想已經越來越被大家接受,但是大家對一些基礎化的東西不是很熟悉,比如基類和子類的調用順序。在這裡我以c#為例給大家講解一下對於一個下面一段代碼 public class baseClass { public string a="baseClass" ; public baseClass() { a="初始化baseClass"; } } public class
Time of Update: 2017-02-28
express|visual 安裝:下了Express Edition幾天了,安裝時碰到了一些問題。原先機器裡裝過VS 2005的預覽版。1.2的.Net Framework和Java#等在控制台的安裝卸載中出現的都能卸掉了。問題出在一直要我卸載Visual Studio .Net Prerequisites,原安裝盤早刪了。最後的解決辦法是在註冊表裡查"Visual Studio .Net
Time of Update: 2017-02-28
看過一本書,題目是《AscpectJ in Action》,正好這一段手上的項目搞一段落,所以有一點點空暇,決定寫一些東西。AOP是Aspect-Oriented Programming的簡寫。曾經為這個Aspect的中文翻譯傷透了腦筋,還有一個相似的AOP,那是Attribute-Oriented
Time of Update: 2017-02-28
1,不徹底的abstract即使是abstract class,也不能對實現的介面的某個成員視而不見,即下面這樣是不允許的:interface in_one{ void A();}abstract class base_one : in_one{ }這一點上還是Java方便,不管C#的初衷是什麼2,out參數與指標的指標out子類不能轉化為out基類,如果允許轉換的化,將無法保證型別安全;即out參數相當於指標的指標,而父類的指標與子類的指標是沒有繼承關係的,所以不能轉化 (The Java
Time of Update: 2017-02-28
今天無聊翻代碼,翻出來一個以前寫的C#截屏的函數...拿出來和大家共用一下.這段代碼是參照網上一段截屏的C++代碼改寫的.只不過把API都聲明了一下而已.聲明的各API也附後.以供參照.如有問題歡迎指出.(Appledotnet@hotmail.com) /// /// 截取部分螢幕/// /// 左上方/// 右下角/// 是否全螢幕/// 傳回值Bitmappublic static Bitmap GetPartScreen(Point P1,Point P2,bool Full){
Time of Update: 2017-02-28
Plugin是一種相當靈活的可擴充、模組化機制,微軟的Application Block不少採用了Plugin結構,本文討論Plugin在C#中的一種實踐。 Plugin是基於統一的介面,在C#中採用Reflection機制產生實現IPlugin的對象。假定介面為IPlugin,以下代碼塊示意動態產生IPlugin對象的程式碼片段,其中dllName是實現IPlugin介面類的dll檔案名稱: public IPlugin LoadPlugin(string
Time of Update: 2017-02-28
今天開始考慮AOP的C#實現,對於靜態Weavor方法迷惑中。在原始碼層級的編織是採用像AspectJ那樣做呢,還是另闢蹊徑?一開始就要讓我頭痛了。AspectJ的方式是:對原始碼進行解析,然後在加入點(JoinPoint)插入Aspcet的代碼,形成中間檔案,再編譯成最終檔案。這種方法產生的效能比較好,有一個缺陷就是如果修改了weaving的規則,就要重新編譯。(或許可以採用某些設計模式來消除這個弱點)另外一種思路就是一開始就採用設計模式,在JontPoint處插入delegate,以後如果需
Time of Update: 2017-02-28
編程|規範 IDesign發布了C#編程規範,小雞射手從Only4Gurus下載瀏覽後決心抽時間翻譯一下,以更好地學習。 目錄內容如下: 1 命名規則和風格 Naming Conventions and Style 2 編碼慣例 Coding Practices 3 項目設定和結構 Project Settings and Structure 4 Framework特別指導 Framework
Time of Update: 2017-02-28
編程|規範 續之三,本文是IDesign C#編程規範的第三章。 3 項目設定和項目結構 Project Settings and Project Structure 1. 總是以4級警告建立項目(圖略)。 Always build your project with warning level 4 2. 在發布版中將警告作為錯誤(注意這不是VS.NET的預設設定)(圖略)。 Treat warning as
Time of Update: 2017-02-28
This is an article on Constructors in C#, for the beginner level programmers. It covers simple constructors, constructors overloading, behaviour of constructors in inheritance, constructor chaining and static constructors. At the end, it contains