现在的位置: 首页 > 综合 > 正文

c# 系列 – 基本知识

2013年08月25日 ⁄ 综合 ⁄ 共 718字 ⁄ 字号 评论关闭

1   string a = null      string b = “” ;之间的区别
      a  是没有分配地址空间的, B是分配了地址空间的。

2  请详述在dotnet中类(class)与结构(struct)的异同:

class   只引用类型,struck 是值类型。

3  写一段  委托类型的代码 ;

关键字 delegate  

使用  步骤 首先声明 delegate   变量  其次,创建delegate 变量  最后 使用 委托。

委托代码
namespace test
{
//声明委托 
public delegate void OnDBOperate(); public class UserControlBase : System.Windows.Forms.UserControl { //委托的实例化 public event OnDBOperate OnNew; private void toolBar_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e) { if (e.Button.Equals(null)) { if (OnNew != null) { OnNew(); } } } } }

委托的经典应用

1、Lambda 表达式。Lambda 表达式有两种存在方式,一是匿名委托,而是表达式树。
2、匿名方法。不指定名称的委托成为匿名委托。有时候非常有用,如在绑定事件处理程序或者创建线程时。
3、多线程同步以及跨线程操作。
4、泛型委托。
5、基于委托的逆变 (Contravariance) 和协变 (Covariance)。
6,窗体中的时间应用。

=====================需要注意的地方==========

声明的委托   和 

抱歉!评论已关闭.