| 网站首页 | JAVA文章 | AppServers | Web开发 | 应用开发 | 资源下载 | 论坛
    学好外语能够获得更多的国外先进编程技术  [enadd  2006年12月25日]        
设为首页 加入收藏 联系站长
您现在的位置: 编程笔记网 >> Web开发 >> 网络编程 >> C# >> CSharpDoc >> 文章正文
C#和VB.net语法对比图            【字体:
C#和VB.net语法对比图
作者:不详    文章来源:网络    点击数:    更新时间:2007-1-20

 

C#

private int _size;







public int Size {



  get {



    return _size;



  }



  set {



    if (value < 0)



      _size = 0;



    else



      _size = value;



  }



} 















foo.Size++;

 

Delegates / Events

VB.NET

 

Delegate Sub MsgArrivedEventHandler(ByVal message



As String) 











Event MsgArrivedEvent As MsgArrivedEventHandler 











'or to define an event which declares a



'delegate implicitly



Event MsgArrivedEvent(ByVal message As String) 











AddHandler MsgArrivedEvent, AddressOf My_MsgArrivedCallback



'Won't throw an exception if obj is Nothing



RaiseEvent MsgArrivedEvent("Test message")



RemoveHandler MsgArrivedEvent, AddressOf My_MsgArrivedCallback















Imports System.Windows.Forms 











'WithEvents can't be used on local variable



Dim WithEvents MyButton As Button



MyButton = New Button 











Private Sub MyButton_Click(ByVal sender As System.Object, _



  ByVal e As System.EventArgs) Handles MyButton.Click



  MessageBox.Show(Me, "Button was clicked", "Info", _



    MessageBoxButtons.OK, MessageBoxIcon.Information)



End Sub

 

C#

 

delegate void MsgArrivedEventHandler(string message); 











event MsgArrivedEventHandler MsgArrivedEvent; 











//Delegates must be used with events in C#











MsgArrivedEvent += new MsgArrivedEventHandler



  (My_MsgArrivedEventCallback);



//Throws exception if obj is null



MsgArrivedEvent("Test message");



MsgArrivedEvent -= new MsgArrivedEventHandler



  (My_MsgArrivedEventCallback); 















using System.Windows.Forms; 











Button MyButton = new Button();



MyButton.Click += new System.EventHandler(MyButton_Click); 











private void MyButton_Click(object sender, 
System.EventArgs e) {   MessageBox.Show(this, "Button was clicked", "Info",     MessageBoxButtons.OK, MessageBoxIcon.Information); }

上一页  [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] 下一页  

文章录入:enadd    责任编辑:enadd 
  • 上一篇文章:

  • 下一篇文章:
  • 发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口
    最新热点 最新推荐 相关文章
  • C# 3.0语言详解之基本的语言…

  • C# 2.0与泛型

  • C# 2.0中泛型编程初级入门教…

  • 关于C#的问答

  • C#中结构与类的区别

  • C#的四个基本技巧

  • C#基础—关于类

  • 漫谈C#编程中的多态与new关键…

  • C# Namespace

  • C# 中的类型转换

  •   网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)
    | 设为首页 | 加入收藏 | 联系站长 | 友情链接 | 版权申明 | 管理登录 |