I  D:

PW:

    

·电话:025-84664270
·电话:025-84664470
·全国:400-8198-518
·Q  Q:368369556
·Q  Q:5813429
·MSN:xunlingsales@
hotmail.com






 
 

·网页设计制作搜索

 
 

首页 >> ASP+ 支持的 C# 和 VB 语法对照表

 

 

ASP+ 支持的 C# 和 VB 语法对照表

 
 

---摘自《ChinaAsp网络》(文/讨饭猫)
ASP+内置支持3种语言:C#,Visual Basic(注意不是VBScript),JScript。下面列出一个简单的C#和VB语法对照表,看看你到底喜欢那个?
C# 语法              VB 语法

定义变量
int x;                 Dim x As Integer
String s;                Dim s As String
String s1, s2;             Dim s1, s2 As String
Object o;                Dim o 'Implicitly Object
Object obj = new Object();       Dim obj As New Object()
public String name;           Public name As String 

输出内容

Response.Write("foo");         Response.Write("foo") 


注释

                    ' This is a comment
                    ' This
// This is a comment          ' is
/* This is a multi-line comment */   ' a 
                    ' multi-line
                    ' comment 

读取数据集合数组

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


定义简单数据集

public String name {
get {
...
return ...;
}
set {
... = value;
}
} 
                   Public Property Name As String
                   Get
                   ...
                   Return
                   ...;
                   End Get
                   Set
                   ... = Value;
                   End Set
                   End Property 

数组

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(3) As String
a(0) = "1"
a(1) = "2"
a(2) = "3"
Dim a(3,3) As String
a(0,0) = "1"
a(1,0) = "2"
a(2,0) = "3"
                ' Array of unspecified bounds (NA in C#)
                Dim a() As String
                a(0,0) = "1"
                a(1,0) = "2"
                a(2,0) = "3"
                Dim a(,) As String
                a(0,0) = "1"
                a(1,0) = "2"
                a(2,0) = "3" 

初始化变量

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 } 

If 结构

if (Request.QueryString != null) {
...
} 
                  If Not (Request.QueryString = Null)
                   ...
                  End If 

Case 结构

switch (FirstName){
case "John" :
...
break;
case "Paul" :
...
break;
case "Ringo" :
...
break;
} 
                  Select (FirstName)
                  case "John" :
                   ...
                  case "Paul" :
                   ...
                   case "Ringo" :
                   ...
                   End Select 

For 循环

for (int i=0; i<3; i++)
a(i) = "test"; 
                  Dim I As Integer
                  For I = 0 To 2
                  a(I) = "test"
                  Next 

While 循环

int i = 0;
while (i<3) {
Console.WriteLine(i.ToString());
i += 1;
} 
                  Dim I As Integer
                  I = 0 Do While I 

字符串操作

String s1;
String s2 = "hello";
s2 += " world";
s1 = s2 + " !!!"; 
                  Dim s1, s2 As String
                  s2 = "hello"
                  s2 &= " world"
                  s1 = s2 & " !!!" 

事件处理

void MyButton_Click(Object sender, EventArgs E) {
...
} 
         Sub MyButton_Click(Sender As Object, E As EventArgs)
          ...
         End Sub
          注意 ByVal 在VB中是省缺参数 

对象操作

MyObject obj = (MyObject)Session["Some Value"];
IMyObject iObj = obj 
                  Dim bj As MyObject
                  Dim iObj As IMyObject
                  obj = Session("Some Value")
                  iObj = CType(obj, IMyObject) 

类型转换

int i = 3;
String s = i.ToString();
double d = Double.Parse(s); 
                  Dim i As Integer
                  Dim s As String
                  Dim d As Double
                  i = 3
                  s = i.ToString()
                  d = CDbl(s)
                  ' 参见 CDbl(...), CStr(...), ... 

类定义和继承

using System;
namespace MySpace {
public class Foo : Bar {
int x;
public Foo() {x = 4; }
public void Add(int x) { this.x += x; }
public int GetNum() { return x; }
}
}
// csc /out:librarycs.dll /t:library library.cs 
                  Imports System
                  Namespace MySpace
                  Public Class Foo : Inherits Bar
                  Dim x As Integer

                  Public Sub New()
                  MyBase.New()
                  x = 4
                  End Sub
                  Public Sub Add(x As Integer)
                  Me.x = Me.x + x
                  End Sub
                  Public Function GetNum() As Integer
                  Return x
                  End Function
                  End Class
                  End Namespace
                  ' vbc /out:libraryvb.dll /t:library library.vb 

(也许是多年来用惯了C的缘故,一直喜欢C那种简练,个性化的风格,文字和符号混合使用,可以让眼睛迅速找到关键所在,避免视线被淹没在复杂的字符串中,所以即使在 ASP 时代,也是坚持使用风格类似的 JScript,现在终于……hehehe…..-讨饭猫)

【来源:本地】【加入时间:2007-12-21 9:07:54】【浏览:次】【关闭窗口

 

上一条:没有上一条了 / 下一条:ASP+的几个特点
 

推荐资讯

 

最新文章

· 动画设计公司网站设计案例 2007-10-19 [广告装潢]
· ASP+ 支持的 C# 和 VB 语法对照表 2007-12-21 [ASP技术]
· web3.0离我们还有多远? 2007-12-20 [网页制作]
· 征途Online源码泄露事件 2007-12-20 [网页制作]
· 小学教师半数收入办网站 2007-12-20 [网页制作]

关于《 ASP+ 支持的 C# 和 VB 语法对照表 》的申明:
·若非特别说明,本文则为本站原创,转载请注明出处"讯领中国",并带上链接:http://www.cxne.com.cn
·本站提供的案例欣赏,并非全部为本公司作品,仅作为比较和报价参考。
·本站内容如果侵犯了您的权利,请与我们联系:025-84664270。我们尊重作者的知识产权和其他保留权利。


 

 
 

 

首页关于我们服务项目技术文库网站案例  | 营销中心友情链接网站地图联系方式

 
 

讯领中国 ®  版权所有 苏ICP备06012455号  地址:南京珠江路675号408