为了正常的体验网站,请在浏览器设置里面开启Javascript功能!

[小学教育]C 和VB语法对照表

2017-12-28 6页 doc 19KB 11阅读

用户头像

is_337177

暂无简介

举报
[小学教育]C 和VB语法对照表[小学教育]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 ...
[小学教育]C 和VB语法对照表
[教育]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 { Public Property Name As String get { Get ... ... return ...; Return...; } End Get set { Set ... = value; ... = Value; } End Property } End Property 数组 String[] a = new String[3]; Dim a(3) As String a[0] = "1"; a(0) = "1" a[1] = "2"; a(1) = "2" a[2] = "3"; a(2) = "3" String[][] a = new String[3][3]; Dim a(3,3) As String a[0][0] = "1"; a(0,0) = "1" a[1][0] = "2"; a(1,0) = "2" a[2][0] = "3"; 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"; Dim s As String = "Hello World" int i = 1 Dim i As Integer = 1 double[] a = { 3.00, 4.00, 5.00 }; 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){ Select (FirstName) case "John" : case "John" : ... ... break; case "Paul" : case "Paul" : .. ... case "Ringo" break; ... case "Ringo" : End Select ... break; } For 循环 Dim I As Integer For I = 0 To 2 for (int i=0; i<3; i++) a(I) = "test" a(i) = "test"; Next While 循环 int i = 0; Dim I As Integer while (i<3) {I = 0 Do While I Console.WriteLine(i.ToString()); i += 1; } 字符串操作 Dim s1, s2 As String String s1; s2 = "hello" String s2 = "hello"; s2 &= " world" s2 += " world"; s1 = s2 & " !!!" 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) Dim i As Integer 类型转换 Dim s As String int i = 3; Dim d As Double String s = i.ToString(); i = 3 double d = Double.Parse(s); 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 和VB语法对照表】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。 本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。 网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。

历史搜索

    清空历史搜索