设为首页 加入收藏 网站搜索 繁體中文 中国建站网 — 站长资源分享平台

C#和VB.net语法对比图

来源:网络收集 作者:佚名 时间:2007-04-26 00:48:44

C#和VB.net的语法相差还是比较大的. 可能你会C#,可能你会VB.

将它们俩放在一起对比一下你就会很快读懂,并掌握另一门语言.

相信下面这张图会对你帮助很大.

 

Comments

VB.NET

'Single line onlyRem Single line only

C#

// Single line/* Multipleline *//// XML comments on single line/** XML comments on multiple lines */

Data Types

VB.NET

'Value TypesBooleanByteChar (example: "A")Short, Integer, LongSingle, DoubleDecimalDate 'Reference TypesObjectStringDim x As IntegerSystem.Console.WriteLine(x.GetType())System.Console.WriteLine(TypeName(x)) 'Type conversionDim d As Single = 3.5Dim i As Integer = CType (d, Integer)i = CInt (d)i = Int(d)

C#

//Value Typesboolbyte, sbytechar (example: 'A')short, ushort, int, uint, long, ulongfloat, doubledecimalDateTime //Reference Typesobjectstringint x;Console.WriteLine(x.GetType())Console.WriteLine(typeof(int)) //Type conversionfloat d = 3.5;int i = (int) d

Constants

VB.NET

Const MAX_AUTHORS As Integer = 25ReadOnly MIN_RANK As Single = 5.00

C#

const int MAX_AUTHORS = 25;readonly float MIN_RANKING = 5.00;

Enumerations

VB.NET

Enum Action  Start  'Stop is a reserved word[Stop]  Rewind  ForwardEnd EnumEnum Status   Flunk = 50   Pass = 70   Excel = 90End EnumDim a As Action = Action.Stop If a <> Action.Start Then _'Prints "Stop is 1"    System.Console.WriteLine(a.ToString & " is " & a)'Prints 70System.Console.WriteLine(Status.Pass)'Prints PassSystem.Console.WriteLine(Status.Pass.ToString())

C#

enum Action {Start, Stop, Rewind, Forward};enum Status {Flunk = 50, Pass = 70, Excel = 90};Action a = Action.Stop;if (a != Action.Start)//Prints "Stop is 1"  System.Console.WriteLine(a + " is " + (int) a); // Prints 70System.Console.WriteLine((int) Status.Pass); // Prints PassSystem.Console.WriteLine(Status.Pass);

Operators

VB.NET

'Comparison=  <  >  <=  >=  <> 'Arithmetic+  -  *  /Mod  (integer division)^  (raise to a power) 'Assignment=  +=  -=  *=  /=  =  ^=  <<=  >>=  &= 'BitwiseAnd  AndAlso  Or  OrElse  Not  <<  >> 'LogicalAnd  AndAlso  Or  OrElse  Not 'String Concatenation& 

C#

//Comparison==  <  >  <=  >=  != //Arithmetic+  -  *  /%  (mod)/  (integer division if both operands are ints)Math.Pow(x, y) //Assignment=  +=  -=  *=  /=   %=  &=  |=  ^=  <<=  >>=  ++  -- //Bitwise&  |  ^   ~  <<  >> //Logical&&  ||   ! //String Concatenation+

Choices

VB.NET

greeting = IIf(age < 20, "What's up?", "Hello") 'One line doesn't require "End If", no "Else"If language = "VB.NET" Then langType = "verbose" 'Use: to put two commands on same lineIf x <> 100 And y < 5 Then x *= 5 : y *= 2   'PreferredIf x <> 100 And y < 5 Then  x *= 5  y *= 2End If 'or to break up any long single command use _If henYouHaveAReally < longLine And _ itNeedsToBeBrokenInto2   > Lines  Then _  UseTheUnderscore(charToBreakItUp) If x > 5 Then  x *= y ElseIf x = 5 Then  x += y ElseIf x < 10 Then  x -= yElse  x /= yEnd If 'Must be a primitive data typeSelect Case color     Case "black", "red"    r += 1  Case "blue"    b += 1  Case "green"    g += 1  Case Else    other += 1End Select

C#

greeting = age < 20 ? "What's up?" : "Hello"; if (x != 100 && y < 5){  // Multiple statements must be enclosed in {}  x *= 5;  y *= 2;} if (x > 5)   x *= y; else if (x == 5)   x += y; else if (x < 10)   x -= y; else   x /= y;//Must be integer or stringswitch (color){  case "black":  case "red":    r++;   break;  case "blue"   break;  case "green": g++;     break;  default:    other++;   break;}

Loops

VB.NET

'Pre-test Loops:While c < 10  c += 1End While Do Until c = 10  c += 1Loop 'Post-test Loop:Do While c < 10  c += 1Loop For c = 2 To 10 Step 2  System.Console.WriteLine(c)Next 'Array or collection loopingDim names As String() = {"Steven", "SuOk", "Sarah"}For Each s As String In names  System.Console.WriteLine(s)Next

[1] [2] [3] [4]  下一页

Tags:

  • 好的评价 如果您觉得好,就请您
      0%(0)
  • 差的评价 如果您觉得差,就请您
      0%(0)
  • 相关文章
    广告赞助

    文章随便看看 设计素材 建站学院 网页模板 视频教程

    网友评论

    共有 0 位网友发表了评论,得分 0 分,平均 0 分    查看完整评论

    用户名: 查看更多评论

    分 值:100分 85分 70分 55分 40分 25分 10分 1分

    内 容:

             通知管理员 验证码: