NameSpace System.CollectionsArrayList可以存放多樣的型態,陣列內元素可以是任何Object可接受的資料型別且永遠都是"一維陣列",常用在存放混合各種資料型別以及存放的個數不確定之情形(ps.陣列須明確知道存放資料個數,以及資料型別都要相同)
宣告:System.Collections.ArrayList Msg = new System.Collections.ArrayList();
使用:Msg.Insert(0,"M0"); //新增
baechang 發表在 痞客邦 留言(0) 人氣(1,331)
組成T-SQL Page分頁查詢字串
1: public string PageSql(string Condition, int CurrentPage, int PageSize, string SortSql, string TableName, string SelectField)
2: {
3: string sql = string.Empty;
4: int PageStart = PageSize * (CurrentPage - 1) + 1;
5: int PageEnd = PageStart + PageSize - 1;
6: if (CurrentPage <= 1)
7: {
8: string Top = PageSize > 0 ? " top " + PageSize : "";
9: sql = string.Format("Select " + Top + " {0} From {1} {2} {3}", SelectField, TableName, Condition, SortSql);
10: }
11: else
12: {
13: sql = "select {0} from(select {1}, ROW_NUMBER() OVER ( {2} ) as Pos from {3} {4}) as RowID where RowID.Pos between " + PageStart + " and " + PageEnd;
14: sql = string.Format(sql, Regex.Replace(SelectField, "([a-zA-Z0-9_]+\\.)", ""), SelectField, SortSql, TableName, Condition);
15: }
16: return sql;
17: }
baechang 發表在 痞客邦 留言(0) 人氣(39)
抓取圖片html tag
1: private List<string> GetImagesInHTMLString(string htmlString)
2: { 3: List<string> images = new List<string>();
4: string pattern = @"<(img)\b[^>]*>";
5:
6: Regex rgx = new Regex(pattern, RegexOptions.IgnoreCase);
7: MatchCollection matches = rgx.Matches(htmlString);
8:
9: for (int i = 0, l = matches.Count; i < l; i++)
10: { 11: images.Add(matches[i].Value);
12: }
13:
14: return images;
15: }
baechang 發表在 痞客邦 留言(0) 人氣(1,053)
在 protected void Page_Load(object sender, EventArgs e) 中為Textbox加入Keydown事件TextBox1.Attributes.Add("onkeydown", JScript事件)Enter的KeyCode是13 以下為程式碼
1: if(event.which || event.keyCode)
2: { 3: if ((event.which == 13) || (event.keyCode == 13))
4: { 5: __doPostBack('Search1$LinkButton1',''); 6: //參照render後的Html原始碼得知要參考的事件控制項觸發事件,加入到Textbox keydown事件中
7: return false;
8: }
9: }
10: else
11: { 12: return true
13: };
14:
15:
16:
17: utton1','');return false;}} else {return true}; ");baechang 發表在 痞客邦 留言(0) 人氣(2,548)
堆疊Stack堆積HeapStack中存放參數,區域變數 (數值型別(傳值))Heap存放物件(參考型別)雖然物件的內容是存放於Heap中,但是物件的參考(指標)是存放於Stack中而Nullable屬於參考型別,所以也等同於上面那一句Boxing意指數值型別複製一份並轉為參考型別例如一個單純的int i = 42;
baechang 發表在 痞客邦 留言(0) 人氣(1,770)
定義:在編譯期間(開發期間)先不固定資料型態,而改由一個自訂名稱之泛型型別來撰寫此類別內或是此方法內的程式碼,等到執行時間,也就是在依照生成物件或是呼叫方法時,傳入或是定義明確的資料型態,並依此資料型態來做處理
1: public class GenericClass<T,U>
2: { 3: public T t;
4: public U u;
5:
6: public GenericClass(T _t, U _u)
7: { 8: t = _t;
9: u = _u;
10: }
11: }
baechang 發表在 痞客邦 留言(0) 人氣(127)
overider 用在繼承物件後,將父物件的方法、屬性、索引子或事件加以實作或是複寫。以下範例抄襲MSDN
1: public class Employee
2: { 3: public string name;
4: protected decimal basepay;
5:
6: public Employee(string name, decimal basepay)
7: { 8: this.name = name;
9: this.basepay = basepay;
10: }
11:
12: public virtual decimal CalculatePay()
13: //virtual這字眼是說自己的這個東西(方法、屬性等等的)被誰繼承去之後,可以給改寫或蹂躪的
14: { 15: return basepay;
16: }
17: }
baechang 發表在 痞客邦 留言(0) 人氣(679)
基於JSON的方便性 先設定WebAPI一定是回傳JSON格式首先要再 Global.asax 檔案的 Application_Start() 事件裡加上GlobalConfiguration.Configuration.Formatters.XmlFormatter.SupportedMediaTypes.Clear();
在html網頁裡面jQquery使用ajax呼叫 :
1: <script>
2:
3: $(document).ready(function () { 4: var json = JSON.stringify({ 5: UUID: "F1AC71F4-B9A8-4BFD-941F-68E21689D263",
6: Name: "UserName",
7: Password: "password",
8: Event: "Evt0001"
9: });
10: $.ajax({ 11: url: "http://localhost:1856/api/TestApI",
12: cache: false,
13: type: 'POST',
14: contentType: 'application/json; charset=utf-8',
15: data: json,
16: statusCode: { 17: 201 /*Created*/: function (data) { 18:
19: }
20: }
21: });
22: });
23: </script>
當然你得在MVC專案的Controller裡面新增一個TestApiController 因為動作行為是Post所以就寫在Post的Functiob裡面
1: public Dictionary<string, string> Post(Dictionary<string, object> value)
2: { 3:
4: return new Dictionary<string, string>()
5: { 6: {"UUID", value["UUID"].ToString()}, 7: {"Name", value["Name"].ToString()}, 8: {"Event", value["Event"].ToString()}, 9: {"Code", "0"}, 10: {"Msg", ""}, 11: {"Link", "http://AD.TEST.com"} 12: };
13: }
如此接上去了.
baechang 發表在 痞客邦 留言(0) 人氣(5,741)

用比較廣義一點的方式來說,其實不論在哪種行業作哪樣子的工作,終究其目的就是在滿足別人的需
求後,進而產生出可以滿足自己需求的東西。所以,是哪個別人呢?或許是老闆、客戶、顧客等等的,而
又是甚麼東西呢?金錢、快樂、榮耀等等,寫到這裡大部分的男生一定"不小心"會想歪掉,呵呵!沒關
係,你是被賀爾蒙害的,不是你的錯,XD。
baechang 發表在 痞客邦 留言(0) 人氣(608)
在C#與Asp.net中以往在要取得 Request["xx"] 或是 Session["xx"] 或是其它有可能為 null 的變數
的值時, 例如:
baechang 發表在 痞客邦 留言(0) 人氣(586)