作者:佚名 文章来源:不详 点击数: 更新时间:2006-6-15
C#和VB.net的语法相差还是比较大的. 可能你会C#,可能你会VB.
将它们俩放在一起对比一下你就会很快读懂,并掌握另一门语言.
相信下面这张图会对你帮助很大.
Comments
VB.NET
'Single line only
Rem Single line only
C#
// Single line
/* Multiple
line */
/// XML comments on single line
/** XML comments on multiple lines */
Data Types
VB.NET
'Value Types
Boolean
Byte
Char (example: "A")
Short, Integer, Long
Single, Double
Decimal
Date
'Reference Types
Object
String
Dim x As Integer
System.Console.WriteLine(x.GetType())
System.Console.WriteLine(TypeName(x))
'Type conversion
Dim d As Single = 3.5
Dim i As Integer = CType (d, Integer)
i = CInt (d)
i = Int(d)
C#
//Value Types
bool
byte, sbyte
char (example: 'A')
short, ushort, int, uint, long, ulong
float, double
decimal
DateTime
//Reference Types
object
string
int x;
Console.WriteLine(x.GetType())
Console.WriteLine(typeof(int))
//Type conversion
float d = 3.5;
int i = (int) d
Constants
VB.NET
Const MAX_AUTHORS As Integer = 25
ReadOnly 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
Forward
End Enum
Enum Status
Flunk = 50
Pass = 70
Excel = 90
End Enum
Dim a As Action = Action.Stop
If a <> Action.Start Then _
'Prints "Stop is 1"
System.Console.WriteLine(a.ToString & " is " & a)
'Prints 70
System.Console.WriteLine(Status.Pass)
'Prints Pass
System.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 70
System.Console.WriteLine((int) Status.Pass);
// Prints Pass
System.Console.WriteLine(Status.Pass);
[8] [9] [10]
