使用 Google 搜尋本站文章:
首頁 | CodeCharge 討論板 | 部落格 | ASP.NET 電子書 | 相簿 | News | 網站導讀 | 聯絡 Allen | 訂閱 RSS
 
since 2004 
 


[影片]如何使用擴充方法替一個既存的資料型別加入自訂功能(2)

By Allen Kuo, 建立日期:2008/02/20 10:25 ,最後修改日期:2011/09/21 09:57
如何為既有型別加入新method,好用的新功能...
    加入書籤: 收進你的MyShare個人書籤

針對既有的型別,例如 String, DateTime, TextBox, DropDownList, DataTable,... 等, 在 .NET 3.0 新增了 Extension Method 的功能, 好讓您能為各型別加入自訂的 method, 例如

string a = allen@xxx.com;
bool b = a.ValidEmail(); //其中ValidEmail()就是自行擴充的method , 用來驗證是否為email

DataTable cities =....;
this.DDL1.BindItems(cities, "ID","CityName"); //就可以將 items 繫結到 dropdownlist 裡

挺方便的功能, 對吧

其他資源: http://www.microsoft.com/taiwan/msdn/elearning/Teaching/vcsharp2008/video5/


回應


姓名: (必填)
Email:
內容: (必填)
驗證碼:   (請輸入圖片中的文字,不區分大小寫)
Copyright © AllenKuo.com , 2000 - 2012, Version 11.08