C和VB語法對照表_第1頁
C和VB語法對照表_第2頁
C和VB語法對照表_第3頁
全文預(yù)覽已結(jié)束

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)

文檔簡介

1、-摘自 ChinaAsp 網(wǎng)絡(luò) (文 /討飯貓 )ASP+內(nèi)置支持 3種語言:C#, Visual Basic (注意不是 VBScript ), JScript。下面列出一個簡 單的C#和VB語法對照表,看看你到底喜歡那個?C# 語法VB 語法定義變量int x;String s;String s1, s2;Object o;Object obj = new Object(); public String name;Dim x As IntegerDim s As StringDim s1, s2 As StringDim o 'Implicitly Object Dim obj A

2、s New Object()Public name As String輸出內(nèi)容Response.Write("foo");注釋/ This is a comment/* This is a multi-line comment */讀取數(shù)據(jù)集合數(shù)組String s=Request.QueryString"Name"String value=Request.Cookies"key"定義簡單數(shù)據(jù)集public String name get return .;set . = value; Response.Write("foo&

3、quot;)' This is a comment' This' isa' multi-line' commentDim s, value As Strings = Request.QueryString("Name") value = Request.Cookies("Key").Value 'Note that default non-indexed properties'must be explicitly named in VBPublic Property Name As StringGe

4、tReturn.;End GetSet. = Value;End PropertyEnd Property數(shù)組Dim a(3) As Stringa(0) = "1"a(1) = "2"a(2) = "3"Dim a(3,3) As Stringa(0,0) = "1"a(1,0) = "2"a(2,0) = "3"String a = new String3; a0 = "1"a1 = "2"a2 = "3"Str

5、ing a = new String33; a00 = "1"a10 = "2"a20 = "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 Stringa(0,0) = "1" a(1,0) = "2" a(2,0) = "3"初始化變量Dim s

6、 As String = "Hello World"Dim i As Integer = 1Dim a() As Double = 3.00, 4.00, 5.00 String s = "Hello World" int i = 1 double a = 3.00, 4.00, 5.00 ; If 結(jié)構(gòu)if (Request.QueryString != null) If Not (Request.QueryString = Null)End IfCase 結(jié)構(gòu)switch (FirstName) case "John" :brea

7、k;case "Paul" :Select (FirstName) case "John" :case "Paul" :break;case "Ringo"break;For循環(huán)for (int i=0; i<3; i+) a(i) = "test"While循環(huán)int i = 0;while (i<3) Co nsole.WriteLi ne(i.ToStri ng();i += 1;字符串操作Stri ng s1;Stri ng s2 = "hello" s2

8、 += " world"s1 = s2 + " !"Dim I As In teger I = 0 Do While IDim s1, s2 As Stri ng s2 = "hello" s2 &= " world"s1 = s2 & " !"事件處理void MyButton_Click(Object sen der, Even tArgs E) Sub MyButton_Click(Se nder As Object, E As Even tArgs)End Sub注意By

9、Val在VB中是省缺參數(shù)對象操作MyObject obj = (MyObject)Session"Some Value"IMyObject iObj = objDim bj As MyObjectDim iObj As IMyObject obj = Session("Some Value") iObj = CType(obj, IMyObject)Dim i As In tegerDim s As Stri ngDim d As Doublei = 3s = i.ToStri ng()類型轉(zhuǎn)換int i = 3;String s = i.ToStrin

10、g(); double d = Double.Parse(s);類定義和繼承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.csImports System Namespace MySpace Public Class Foo : Inherits Bar Dim x As IntegerPublic Sub New() MyBase.New() x = 4 End SubPublic 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 ' v

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

最新文檔

評論

0/150

提交評論