目前分類:C# (87)

瀏覽方式: 標題列表 簡短摘要


VB:

createps 發表在 痞客邦 留言(0) 人氣()


除了一般的Random方式以外

createps 發表在 痞客邦 留言(0) 人氣()

C# 字串變數, 如何包含雙引號或反斜線

createps 發表在 痞客邦 留言(0) 人氣()

class TestRegularExpressions
{
    static void Main()
    {
        string[] sentences = 
        {
            "cow over the moon",
            "Betsy the Cow",
            "cowering in the corner",
            "no match here"
        };

        string sPattern = "cow";

        foreach (string s in sentences)
        {
            System.Console.Write("{0,24}", s);

            if (System.Text.RegularExpressions.Regex.IsMatch(s, sPattern, System.Text.RegularExpressions.RegexOptions.IgnoreCase))
            {
                System.Console.WriteLine(" (match for '{0}' found)", sPattern);
            }
            else
            {
                System.Console.WriteLine();
            }
        }
    }
}
 
 

輸出

       cow over the moon  (match for 'cow' found)
       Betsy the Cow  (match for 'cow' found)
       cowering in the corner  (match for 'cow' found)
       no match here

createps 發表在 痞客邦 留言(0) 人氣()

宣告:


createps 發表在 痞客邦 留言(0) 人氣()

 System.Diagnostics.Process.Start("http://tw.yahoo.com/?hpp=r1b");


createps 發表在 痞客邦 留言(0) 人氣()

判斷字串裡面是否有數字
      static  bool isnumeric(string str)

createps 發表在 痞客邦 留言(0) 人氣()

//十進制轉二進制
Console.WriteLine(Convert.ToString(69, 2));

createps 發表在 痞客邦 留言(0) 人氣()


            Process thisProc = Process.GetCurrentProcess();

createps 發表在 痞客邦 留言(0) 人氣()

我們必須開門見山地說,在相同字串的許多操作上,使用 StringBuilder 類別會比使用一個 String 物件來得更有效率。 

大家務必瞭解,System.String 資料型別(或是說 String 物件)代表的是一種不變的字串,也就是說,一旦您設定其值,您就不能更改它。如果您嚐試要插入、刪除或更改字串的任何部分,唯一的方式就是去建立一個新的字串。說得更專業點,每次字串資料變更時,記憶體中該字串原來的表示法就會被破壞掉,並建立內含新字串資料的新表示法,此舉會引發對記憶體的配置作業以及對記憶體的反配置作業。當然,這些作業都是在幕後完成的,因此真正的成本並不會立刻顯現。配置與反配置記憶體會加重 Common Language RuntimeCLR)裡記憶體管理和記憶體回收的相關工作,所以絕對是要付出代價的,直接的影響,就是增了處理時間。這種情況在迅速地接連配置和反配置佔有大塊記憶體的字串時尤其明顯,就像在大量字串串連時所發生的情況一樣。雖然這種情形在單一使用者環境裡不會帶來任何問題,但是在伺服器的環境裡使用時(比方說,在 Web 伺服器上執行的 ASP.NET® 應用程式中),卻可能在效能與延展性上造成極為嚴重的問題。 

createps 發表在 痞客邦 留言(0) 人氣()

VB.NET:ParamArray

public function getAvr(ByVal ParamArray marks() As Integer) As Double

createps 發表在 痞客邦 留言(0) 人氣()

這一招用在Socket資料傳遞上面

     byte[] b = System.Text.Encoding.Unicode.GetBytes("test test \t a");

createps 發表在 痞客邦 留言(0) 人氣()

寫了一個關機程式,可以設定時間倒數,時間到關機

以下是下載處:(放在免費空間)

createps 發表在 痞客邦 留言(0) 人氣()

TimeSpan 


createps 發表在 痞客邦 留言(0) 人氣()

TcpClient.Connected 屬性

取得值,指出 TcpClient 的基礎 Socket 是否已連接至遠端主機。

屬性值

如果最近一次的作業是將 Client 通訊端連接至遠端資源,則為 true,否則為 false

Connected 屬性會取得上次 I/O 作業的 Client 通訊端連接狀態。當它傳回 false 時,即表示 Client 通訊端不是從未連接過,就是不再連接了。

createps 發表在 痞客邦 留言(0) 人氣()

 string[] 版號 = Application.ProductVersion.Split('.');

 string 版本 = 版號[0] + "." + 版號[1] + "." + 版號[2];

createps 發表在 痞客邦 留言(0) 人氣()

You have a TextBox control on your Windows Forms application and need to detect Enter. The TextBox allows your users to type letters into it, and you need to detect when a certain key is pressed. Our solution involves the KeyDown event in our C# Windows Form. We use the KeyDown event for our code.

Using KeyDown event

Open designer and click on TextBox. In the Visual Studio 2008 designer, click on your TextBox control in the form display. You will see the Properties Pane. Next, click on the lightning bolt icon. This icon stands for events. In the event tab, scroll to KeyDown, and double click in the space to the right. New code like that highlighted below will appear.

createps 發表在 痞客邦 留言(0) 人氣()

C#:
前面補0的數字字串

createps 發表在 痞客邦 留言(0) 人氣()

同步發表於Google Blogger

     Dictionary<string, object> tagDictionary = new Dictionary<string, object>();

createps 發表在 痞客邦 留言(0) 人氣()

//=========================================================================================

不取得子目錄的話用這個:

createps 發表在 痞客邦 留言(0) 人氣()