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

 

C#

// Pass by value (in, default), reference



//(in/out), and reference (out)



void TestFunc(int x, ref int y, out int z) {



  x++;



  y++;



  z = 5;



} 



















int a = 1, b = 1, c; // c doesn't need initializing



TestFunc(a, ref b, out c);



System.Console.WriteLine("{0} {1} {2}", a, b, c); // 1 2 5 











// Accept variable number of arguments



int Sum(params int[] nums) {



  int sum = 0;



  foreach (int i in nums)



    sum += i;



  return sum;



} 











int total = Sum(4, 3, 2, 1); // returns 10 











/* C# doesn't support optional arguments/parameters.



Just create two different versions of the same function. */



void SayHello(string name, string prefix) {



  System.Console.WriteLine("Greetings, " 
+ prefix + " " + name); } void SayHello(string name) {   SayHello(name, ""); }

 

Exception Handling

VB.NET

 

'Deprecated unstructured error handling



On Error GoTo MyErrorHandler



...



MyErrorHandler: System.Console.WriteLine(Err.Description)







Dim ex As New Exception("Something has really gone wrong.")



Throw ex 











Try



  y = 0



  x = 10 / y



Catch ex As Exception When y = 0 'Argument and When is optional



  System.Console.WriteLine(ex.Message) 



Finally



  DoSomething() 



End Try

上一页  [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条。评论内容只代表网友观点,与本站立场无关!)
    | 设为首页 | 加入收藏 | 联系站长 | 友情链接 | 版权申明 | 管理登录 |