日期:2011-05-08 浏览次数:20639 次
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 = " |