C#

C# 


[**]static 方法 只能存取外部的static 變數
//Example.cs
namespace TetrisServer
{
    class Program
    {
        static private string ip;
        private int port;
        static void Main(string[] args)
        {
            ip = "XXX"; //OK
            port = 57; // fail
        }
    }
}

字串處理

1.

string str = "asdaa asd qwe";
string str1 = str.Substring(0,str.IndexOf(" ")); //=> "asdaa"
string str2 = str.Substring(str.IndexOf(" ")+1); //=> "asd"

2.

string str = "asdqwe asd sad";
string[] strr = str.Split(new char[] { ' ' }); //=> strr = "asdqwe","asd","sad"
-----------------------------------------------------------------------------------------------------------------------
string 加入換行
string str = str + System.Environment.NewLine;
-----------------------------------------------------------------------------------------------------------------------

c# LinkedList:

1. array to LinkedList<T>

int[] a = new int[5];
LinkedList<int> list = new LinkedList<int> ();

//正確
foreach(int value in a){
    list.AddLast(value);
}

//錯誤
list =  a.ToList();

C# 執行緒


Thread Thr  = new Thread(func);//func 必須是 static void func(); 沒有引數、return 值 否則會跳出 "無法從方法群組...."的錯誤

Thr.Start();//要Start 才會開始執行

FormClosedClose 事件

新增:

this.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.f2closed);

System.Convert

int i = System.Convert.Int32("123"); //=> i=123

--------------------------------------------------------------
...ToList().ForEach( b => b. ... = ...);

留言

這個網誌中的熱門文章

組合語言 Assembly Language