360度全方位比较 c# 和 VB

2008-02-23 05:24:18来源:互联网 阅读 ()

新老客户大回馈,云服务器低至5折

原帖及讨论:http://bbs.bc-cn.net/dispbbs.asp?BoardID=117&ID=97286

1 变量声明

int x;
String s;
String s1, s2;
Object o;
Object obj = new Object();
public String name;


Dim x As Integer
Dim s As String
Dim s1, s2 As String
Dim o 'Implicitly Object
Dim obj As New Object()
Public name As String

2 语句

Response.Write("foo");


Response.Write("foo")


3 注释

// This is a comment

/*
This
is
a
multiline
comment
*/


' This is a comment

' This
' is
' a
' multiline
' comment

4 访问索引属性

String s = Request.QueryString["Name"];
String value = Request.Cookies["key"];


Dim s, value As String
s = Request.QueryString("Name")
value = Request.Cookies("Key").Value
'Note that default non-indexed properties
'must be explicitly named in VB


5 声明索引属性

// Default Indexed Property
public String this[String name] {
get {
return (String) lookuptable[name];
}
}

' Default Indexed Property
Public Default ReadOnly Property DefaultProperty(Name As String) As String
Get
Return CStr(lookuptable(name))
End Get
End Property


6 声明简单属性

public String name {

get {
...
return ...;
}

set {
... = value;
}

}


Public Property Name As String

Get
...
Return ...
End Get

Set
... = Value
End Set

End Property


7 声明和使用枚举

// Declare the Enumeration
public enum MessageSize {

Small = 0,
Medium = 1,
Large = 2
}

// Create a Field or Property
public MessageSize msgsize;
// Assign to the property using the Enumeration values
msgsize = Small;




' Declare the Enumeration
Public Enum MessageSize

Small = 0
Medium = 1
Large = 2
End Enum

' Create a Field or Property
Public MsgSize As MessageSize

' Assign to the property using the Enumeration values
MsgSize = small


8 枚举集合

foreach ( String s in coll ) {
...
}


Dim S As String
For Each S In Coll
...
Next


9 声明和使用方法

// Declare a void return function
void voidfunction() {
...
}

// Declare a function that returns a value
String stringfunction() {
...
return (String) val;
}

// Declare a function that takes and returns values
String parmfunction(String a, String b) {
...
return (String) (a b);
}

// Use the Functions
voidfunction();
String s1 = stringfunction();
String s2 = parmfunction("Hello", "World!");



' Declare a void return function
Sub VoidFunction()
...
End Sub

' Declare a function that returns a value
Function StringFunction() As String
...
Return CStr(val)
End Function

' Declare a function that takes and returns values
Function ParmFunction(a As String, b As String) As String
...
Return CStr(A & B)
End Function

' Use the Functions
VoidFunction()
Dim s1 As String = StringFunction()
Dim s2 As String = ParmFunction("Hello", "World!")


10 自定义属性

// Stand-alone attribute
[STAThread]

// Attribute with parameters
[DllImport("ADVAPI32.DLL")]

// Attribute with named parameters
[DllImport("KERNEL32.DLL", CharSet=CharSet.Auto)]


' Stand-alone attribute
<STAThread>

' Attribute with parameters
<DllImport("ADVAPI32.DLL")>

' Attribute with named parameters
<DllImport("KERNEL32.DLL", CharSet:=CharSet.Auto)>


11 数组

String[] a = new String[3];
a[0] = "1";
a[1] = "2";
a[2] = "3";

String[][] a = new String[3][3];
a[0][0] = "1";
a[1][0] = "2";
a[2][0] = "3";


Dim a(2) As String
a(0) = "1"
a(1) = "2"
a(2) = "3"

Dim a(2,2) As String
a(0,0) = "1"
a(1,0) = "2"
a(2,0) = "3"


12 初始化

String s = "Hello World";
int i = 1;
double[] a = { 3.00, 4.00, 5.00 };


Dim s As String = "Hello World"
Dim i As Integer = 1
Dim a() As Double = { 3.00, 4.00, 5.00 }


13 If 语句
if (Request.QueryString != null) {
...
}


If Not (Request.QueryString = Nothing)
...
End If


14 Case 语句
switch (FirstName) {
case "John" :

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇: C 中需要(或禁止)对象产生于heap中

下一篇: 单链表的c语言实现(1)