因为工作原因,自学会了vb后陆续接触了其它语言,在工作中经常需要与各家使用不同语言公司的开发人员做程序对接,初期特别需要一个各种语法的对照比,翻看了网络上已有高人做了整理,自己在他基础上也整理了一下,摘抄如下(最后附上原作,网上也可以找到):

类别

Vb6 & Vb.Net

Delphi

C#

语法

不区分大小写

不区分大小写

区分大小写

数据类型

数据     关键字    占用字节      类型符

整型          integer

长整型        long

单精度型      single

双精度型      double

货币型        currency

字节型        byte

字节型        string

布尔型        boolean

日期型        date

8对象型       object

变体型        variant

定义变量/初始化变量

Dim intA as Integer

Dim strA as String

Dim lngA as Long

Dim strA As String = "Hello World"

Dim intS As Integer = 1

Dim douA() As Double = { 3.00, 4.00, 5.00 }

Var

intA:Integer;

strA:String;

lngA:Long;

var

strA: String;

intA: Integer;

douA: array of double = {3.00, 4.00, 5.00}

Int intA

String strA

Long lngA

String strA = "Hello World";

int intA = 1

double[] douA = { 3.00, 4.00, 5.00 };

运算符

+ &

Chr13 chr10

数组应用

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"

Dim a(2) As Integer

a(0) = 0

a(1) = 1

For i = 0 To 2 Step 1

Print a(i)

Next i

var

a[0..2]: string

a[0..2,0..2]: String

begin

a[0] := ‘1’;

a[1] := ‘2’;

a[2] := ‘3’;

a[0,0] := ‘1’;

a[1,0] := ‘2’;

a[2,0] := ‘3’;

End;

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"; 

定义数据集

Public Property Name As String

Get

...

Return ...;

End Get

Set

... = Value;

End Set

End Property

Public Record Name: String;

Function GetName: String; Begin

...;

Result := …;

End;

Procedure SetName(Value: String); Begin

… := Value;

End;

End

public String name

{

get{

...

return ...;

}

set{

... = value;

}

} 

对象的操作

Dim bj As MyObject = Session("Some Value")

Dim iObj As IMyObject = CType(obj, IMyObject)

var

bj: MyObject;

iObj: IMyObject;

begin

obj := Session(‘Some Value’);

iObj = Obj as IMyObject;

end;

MyObject obj = (MyObject)Session["Some Value"];

IMyObject iObj = obj;

字符串操作

Dim s1, s2 As String

s2 = "hello"

s2 &= " world"

s1 = s2 & " !!!" 

<!--[if !supportlinebreaknewline]-->

<!--[endif]-->

var

s1, s2: String;

begin

s2 := ‘hello’;

s2 := s2 + ‘world’;

s1 := s2 + ‘!!!’;

End;

String s1;

String s2 = "hello";

s2 += " world";

s1 = s2 + " !!!";

类型转换&

Format

Dim i As Integer = 3

Dim s As String = i.ToString()

Dim d As Double = Double.Parse(s):

var

i: Integer;

s: String;

d: Double;

begin

i := 3;

s = i.ToString();

d := Double.Parse(s);

end;

int i = 3;

String s = i.ToString();

double d = Double.Parse(s);

代码注释

' 2013-06-07 商超 添加申请单函数

'================================

'取报告内容,得到电子申请单

'================================

折叠代码

#Region “读取数据列表”

#End Region

// 2013-06-07 商超 添加申请单函数    

/* 取得内容

得到电子申请单*/

// 2013-06-07 商超 添加申请单函数     

/* 取得内容

得到电子申请单*/

输入输出或提示内容

Dim n as long

N= Val(InputBox("请输入一个数:"))

Dim n

n = MsgBox("是:添加项目 否:删除项目", 52, "提示信息")

If n = vbYes Then

Dim Add As String

Add = InputBox("请输入添加项目并点击确定后继续", "添加项目")

If Add = "" Then

Exit Sub

End If

Msgbox (“您好!”)

Debug.print (“您好!”)

Console.writeline(“您好!”)

showMessage(“您好!”);

MessageBox(Handle, PChar('不能备份到该目录 ' + path), PChar(MDialogMsg), MB_ICONINFORMATION or MB_OK)

If语句

‘判断是否为空或者指定值

‘判断按键

Dim strUser as string

If strUser=”管理员” then

Msgbox “您是”+strUser

End if

If Not (Request.QueryString = Null)

...

End If 

<!--[if !supportlinebreaknewline]-->

<!--[endif]-->

if a > 3 then

msgbox "a"

end if

if a = "" then

msgbox "a"

else

msgbox "b"

end if

if a ="" then

msgbox "a"

elseif

msgbox "b"

else

msgbox "c"

end if

strUser:string;

If (strUser=’管理员’) then

Showmessage(‘您是’+strUser);

If Not (Request.QueryString = Null) then

begin

...

End;

//测试If Then语句//

procedure TForm1.Button6Click(Sender: TObject);

var

strSql: string;

begin

strSql := 'Select';

if strSql = 'Select' then

showmessage(PChar(strSql))

else

showmessage('Sql语句不对!')

end;

//输入值后按回车//

procedure TForm1.Edit1KeyDown(Sender: TObject; var Key: Word;

Shift: TShiftState);

begin

if (Key = VK_RETURN) then

begin

Button7Click(Sender); //直接调用Button1的事件处理程序完成相同的功能

end;

end;

begin

if key = #8 then

exit;

if not ((key >= '0') and (key <= '9')) then

key := #0;

end;

if (Request.QueryString != null)

{

...

} 

If Else 语句

Case语句

Select (FirstName)

case "John" :

...

<!--[if !supportlinebreaknewline]-->

<!--[endif]-->

case "Paul" :

...

case "Ringo" :

...

End Select

select case index

case  0

msgbox "a"

case  1

msgbox "b"

end select

Case FirstName of

‘John’:

...

‘Paul’:

‘Ringo’:

End

//测试Case语句//

procedure TForm1.Button5Click(Sender: TObject);

var

i: ShortInt;

begin

i := random(3);

case i of

//0:showmessage('测试零');; 符号错误

0: showmessage('测试一');

1: showmessage('测试二');

2: showmessage('测试三');

else

showmessage('测试完成');

end

end;

switch (FirstName){

case "John" :

...

break;

case "Paul" :

...

break;

case "Ringo" :

...

break;

}

For循环

Dim I As Integer

For I = 0 To 2

 a(I) = "test"

Next

for i = 0 to list.count - 1 step  0

msgbox  list(i)

Next

Var

I: Integer;

Begin

For I := 0 to 2 do

A[i] := ‘test’;

End;

//测试For循环//

procedure TForm1.Button2Click(Sender: TObject);

var

I: Integer;

Tot: Integer;

begin

I := 0;

Tot := 0;

for i := 0 to 10 do

begin

Tot := Tot + i

end;

showMessage(IntToStr(Tot));

end;

procedure TForm1.btn1Click(Sender: TObject);

var

i:Integer;

begin

for i:=0 to lst1.Count-1 do

begin

ShowMessage(lst1.Items[i]);

end;

lst1.Items.Clear;

end;

for (int i=0; i<3; i++)

a(i) = "test";

While循环

Dim I As Integer

I = 0

Do While I < 3

Console.WriteLine(i.ToString());

I = I + 1

Loop

Var

I: Integer;

Begin

I := 0;

While i< 3 do

Begin

Console.WriteLen(i.ToString());

I := I + 1;

End;

End;

//测试While语句//

procedure TForm1.Button3Click(Sender: TObject);

var

i: ShortInt;

begin

i := 0;

while i < 10 do

begin

i := i + 1;

showmessage(IntToStr(i));

end;

end;

int i = 0;

while (i<3)

{

Console.WriteLine(i.ToString());

i += 1;

}

With语句

With list

.list(0)=”是我的”

.Add

End with

rs.Open "man", cn, adOpenKeyset, adLockOptimistic

With rs

.AddNew

.Fields("标题") = Trim(Text1.Text)

.Fields("类别") = Trim(Combo1(2).Text)

.Fields("类型") = Trim(Combo1(0).Text)

If Check2.Value = 1 Then

.Fields("内容") = Trim(RichTextBox1.Text)

.Fields("内容2") = Trim(RichTextBox1.TextRTF)

Else

.Fields("内容") = Trim(RichTextBox1.Text)

.Fields("内容2") = Null

End If

.Fields("日期") = Format(DTPicker1.Value, "short date") 'CStr(Format(DTPicker1.Value, "YYYY-MM-DD "))

.Update

End With

with TOpenPictureDialog.Create(nil) do

begin

Filter:='*.bmp|*.bmp';

if Execute then

image1.Picture.LoadFromFile(filename);

Free;

end;

防错语句

on error goto Err:

Try

Castch

End try

try

edtIP.text:=iniinfo.readstring('Size','dbIP','');

Finally

freeAndNil(IniInfo);

end;

//测试Repeat语句//

procedure TForm1.Button4Click(Sender: TObject);

var

i: ShortInt;

begin

i := 0;

repeat

i := i + 1;

showmessage(IntToStr(i))

until i = 10;

end;

退出和关闭

Exit sub

Eixt Function

Close

End

exit;

Self.Close;

过程及函数调用

'调用面积计算过程

Private Sub Add_Click()

Call subcompute(txtLength, txtWidth)

End Sub

'定义一个计算面积的函数,有两个参数,返回计算结果

Private Function subcomputearea(Length As Long, Width As Long)      'length,width都是形式参数

subcomputearea = Length * Width

End Function

'调用计算面积函数

Private Sub Add_Click()

txtResult.Text = F(Val( txtResults.Text))

End Sub

'面积计算函数

Function F(n As Integer) As Single

If n > 1 And n <= 30 Then

F = n * F(n - 1)

Else

F = 1

End If

End Function

递归过程

Private Sub Command8_Click()

Text2.Text = F(Val(Text1.Text))

End Sub

Function F(n As Integer) As Single

If n > 1 And n <= 30 Then

F = n * F(n - 1)

Else

F = 1

End If

End Function

interface //单元的接口部分可在接口部分声明变量、常量、数据类型、过程、函数,结束于implementation的开始部分//

{

//一个简单的函数//

function GetAverage(num:integer;total:Double):Double;

begin

GetAverage := total / num;  //Result := total / num;

end;

//一个简单的过程//

procedure GetResult()      //procedure SetDate(Year: Integer; Month: Integer; Day: Integer); or procedure SetDate(Year, Month, Day: Integer);

begin

GetResult:=3*3;

end;

常用内部函数(字符串函数)

-字符串函数

Mid

Right

Left

Trim

Rtrim

Ltrim

len

Instr

Squit

-转换函数

Char

Val

asc

char

-日期时间函数

Date

Now

Timer

Year/month/day

Hour/minute/second

-判断函数

Isnull

isnumberic

-随机函数

Rnd

-格式化函数

Copy:  

S := ’’I Love China!’’;

  //下面将获取I Love China中的“Love”字符串。

  MyStr := Copy(S, 3, 4);

Concat:

S1 := Concat(’’A’’, ’’B’’); // 连接两个字符串,S1变量等于AB。

  S := ’’I Like Reading CPCW.’’;

  // 下面的代码将删除S变量中的“C”字符。

Delete:

  Delete(S, 16, 1);

  end;

  此时S变量则是I Like Reading PCW.(“C”已经不存在了)。

LeftStr

Length

MidStr

Pos:

  nPos: Integer; // 用于保存查找的字符所在位置

  begin

  nPos := Pos(’’Like’’, ’’I Like Reading!’’);

RightStr:

A := RightStr(S, 3); // 从最右边开始,获取右边的三个字符。因此A变量则等于ger。

Trim

TrimLeft

TrimRight

UpperCase

LowerCase

Low

High

Insert

类的定义和继承

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 

unit MySpace

interface

uses  System;

type

Foo = Class(Bar)

private

x: integer;

public

procedure Create; override; //构造函数

procedure Add(x: Integer);

function GetNum: Integer;

end;

implementation

procedure Foo.Create;

begin

inherited;  x := 4;

end;

procedure Foo.Add(x: Integer); begin

Self.x := Self.x + x;

end;

function Foo.GetNum: Integer; begin

Result := x;

end;

end;

using System;

namespace MySpace

{

public class Foo : Bar

{

<!--[if !supportlinebreaknewline]-->

<!--[endif]-->

int x;

public Foo() {x = 4; } //构造函数

<!--[if !supportlinebreaknewline]-->

<!--[endif]-->

public void Add(int x) { this.x += x; }

<!--[if !supportlinebreaknewline]-->

<!--[endif]-->

public int GetNum() { return x; }

<!--[if !supportlinebreaknewline]-->

<!--[endif]-->

}

}

// csc /out:librarycs.dll /t:library library.cs

事件处理

Sub Button1_Click(Sender As Object, E As EventArgs)

...

End Sub

‘ByVal 在VB中对象是是缺省参数传递方式

procedure Button1OnClick(Sender: Object;E: EventArgs);

begin

...

end;

‘ByRef 在Pascal中对象是缺省参数传递方式

btnSearchClick(Sender); //直接调用Button1的事件处理程序完成相同的功能

void Button1_Click(Object sender, EventArgs E)

{

...

} 

‘ByRef 在C#中对象是是缺省参数传递方式

操作数据库的增删改查应用

(Access Sql Mysql Oracle )

try

conADOConn.Connectionstring :=

'Provider=SQLOLEDB.1;Password=itpschina;Persist Security Info=True;User ID=sa;Initial Catalog=Study;Data Source=.';

conADOConn.Open;

//Showmessage('连接数据库成功!');

qryAdoQ.SQL.Clear;

qryAdoQ.SQL.Add('select * from Man');

qryAdoQ.Open;

except

Showmessage('无法连接数据库!');

exit;

end;

日志记录函数

//写入日志文件//

procedure WriteLog(ErrStr:String);

var

LogFilename: String;

LogFile: TextFile;

begin

LogFilename:=ExtractFilePath(ParamStr(0)) + 'LOG_' + FormatDateTime('yyyymmdd',Now) + '.LOG';

AssignFile(LogFile, LogFilename);

if FileExists(LogFilename) then Append(LogFile)

else Rewrite(LogFile);

Writeln(Logfile,DateTimeToStr(now)+': '+ErrStr);

CloseFile(LogFile);

end;

Ini的读写

Txt的读写

var

iniinfo:TIniFile;

getdir(0,dir); //获取程序所在路径地址

iniInfo:=TInIFile.Create(dir+'\Size.INI');

edtIP.text:=iniinfo.readstring('Size','dbIP','');

iniInfo.WriteString('Size','dbIp',edtIp.Text);

加密解密字符串

//字符串加密与解密函数//

//解密字符串//

function E_code(S:string):String;

var

n,i:integer;

str:string;

begin

n:=length(s);

str:='';

for i:=1 to n do

begin

str:=str+char(Ord(s[i])+2);

end;

E_code:=str;

end;

//加密字符串//

function D_code(s:string):String;

var

n,i:integer;

str:string;

begin

n:=length(s);

str:='';

for i:=1 to n do

begin

str:=str+char(ord(S[i])-2);

end;

D_code:=str;

end;

Xml文件的读写

本地文件读写、打开文件选择框

'///导出文件///

Private Sub Command8_Click()

Dim A As String

A = Text1.Text

Dim n

n = MsgBox("是否导出?", 52, "提示信息")

If n = vbYes Then

Open "D:\\" & A & ".rtf" For Output As #1 '新建文件

Print #1, RichTextBox1.Text

Close #1

MsgBox "文件已经存储在D:\,文件名为" & A & "", 64, "提示信息"

ElseIf n = vbNo Then

MsgBox "操作取消", 64, "提示信息"

Exit Sub

End If

End Sub

'///导入文件///

Private Sub Command9_Click()

Open "D:\给疯狂下资料的朋友们提个醒!.txt" For Input As #1

Dim A

Do While EOF(1) = False

Line Input #1, A

RichTextBox1 = RichTextBox1 & A & vbCrLf                            '这样就好了,要把数据连接起来,否则text只等于最后一行

Loop

Close

End Sub

'///导入文件///

Private Sub mnuOpen_Click()

CommonDialog1.FileName = ""

CommonDialog1.Filter = "*.txt|*.txt|*.rtf|*.rtf|*.*|*.*"

CommonDialog1.DialogTitle = "打开文件"

CommonDialog1.CancelError = True                        '捕获 取消 错误时得先设置为true 然后再showsave

On Error GoTo ErrorHandler

CommonDialog1.ShowOpen

Text1.Text = Left(CommonDialog1.FileTitle, Len(CommonDialog1.FileTitle) - 4)

RichTextBox1.LoadFile CommonDialog1.FileName, 1

ErrorHandler:

Exit Sub

End Sub

'///选择数据库///

Private Sub SelData_Click()

CommonDialog1.FileName = ""

CommonDialog1.InitDir = App.Path                        '设置缺省路径

CommonDialog1.Filter = "*.mdb|*.mdb|"

CommonDialog1.DialogTitle = "选择数据库"

CommonDialog1.CancelError = True                        '捕获 取消 错误时得先设置为true 然后再showsave

On Error GoTo ErrorHandler

CommonDialog1.ShowOpen

entry$ = Trim(CommonDialog1.FileName)

dataname = Trim(CommonDialog1.FileName)

R = WritePrivateProfileString("数据库", "库名", entry, iniPath)

If R <> 1 Then MsgBox "写入出错!"

If selectdate = True Then

Combo1(0).Clear

Call Form_Load

Else

Call Main

End If

ErrorHandler:

Exit Sub

End Sub

with TOpenPictureDialog.Create(nil) do

begin

Filter:='*.bmp|*.bmp';

if Execute then

image1.Picture.LoadFromFile(filename);

Free;

end;

文件路径操作

Dir

App.path

无边框窗体移动

颜色值函数

屏幕位置分辨率


Pascal
VBC#Java四种语法对照表

ASP.NET支持的几种语言:c#.net,vb.net,delphi.net(非内置支持),由于在.net框架下,所有的语言均使用同一个类库,因此功能上是基本上一模一样,只语法上各不相同。

.net与java为两大阵营,为了比较,在此列出一个简单的语法对照表,看看你到底喜欢那个?

类别

delphi.net语法

vb.net 语法(语法不区分大小写)

c#.net 语法

java

语法

不区分大小写

不区分大小写

区分大小写

区分大小写

定义变量

Var
x: Integer;

s: string;

s1, s2: string;

o: TObject;

obj: TObject; obj := TObject.Create;

Public property name: String;

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 

int x;

String s;

String s1, s2;      

Object o;

Object obj = new Object();

public String name;

int x;

String s;

String s1, s2;      

Object o;

Object obj = new Object();

public String name;

输出内容

Response.write(‘foo’);

Response.Write("foo")

Debug.print ("foo")

Response.Write("foo");

Response.Write("foo");

注释

// This is a comment     

/* This is a 
multi-line 
comment */

' This is a comment
' This is a

' multi-line
' comment

// This is a comment

/* This is a 
multi-line 
comment */

// This is a comment

/* This is a 
multi-line 
comment */

读取数据集合数组 
<!--[if !supportlinebreaknewline]-->
<!--[endif]-->

var

s, value: String

begin

s := Request.QueryString[‘Name’];

Value := Request.Cookies(‘Key’).Value;

end;

Dim s as String = Request.QueryString("Name")

Dim value As String = Request.Cookies("Key")
<!--[if !supportlinebreaknewline]-->
<!--[endif]-->

String s=Request.QueryString["Name"];

String value=Request.Cookies["key"]; 

String s = request. getParameter("Name");

String value;

Cookie ck = null;

Cookie args[] = Request.getCookies();

for(int i = 0; i<args.length; i++){

ck = args[i];

if(ck.getName().equals("key "))

value = ck.getValue();

}

字符串操作

var

s1, s2: String;

begin

s2 := ‘hello’;

s2 := s2 + ‘world’;

s1 := s2 + ‘!!!’;

End;

Dim s1, s2 As String 
s2 = "hello" 
s2 &= " world" 
s1 = s2 & " !!!" 
<!--[if !supportlinebreaknewline]-->
<!--[endif]-->

String s1; 
String s2 = "hello"; 
s2 += " world"; 
s1 = s2 + " !!!";

String s1; 
String s2 = "hello"; 
s2 += " world"; 
s1 = s2 + " !!!";

     原作如下:Pascal、VB、C#、Java四种语法对照表


类别

delphi.net语法

vb.net 语法(语法不区分大小写)

c#.net 语法

java

初始化变量

var

s: String;

I: Integer;

A: array of double = {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 } 

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

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

定义简单数据集

Public Record Name: String;

Function GetName: String; Begin

...;

Result := …;

End;

Procedure SetName(Value: String); Begin

… := Value;

End;

End

Public Property Name As String

Get 
... 
Return ...; 
End Get

Set

... = Value; 
End Set

End Property 

public String name


get{
... 
return ...; 
}

set{
... = value; 
}

} 

private String name;

public String getName(){

return name;

}

public void setName(String name){

this.name = name;

}

数组

var

a[0..2]: string

a[0..2,0..2]: String

begin

a[0] := ‘1’;

a[1] := ‘2’;

a[2] := ‘3’;

a[0,0] := ‘1’;

a[1,0] := ‘2’;

a[2,0] := ‘3’;

End;

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"

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"; 

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";

对象操作

var

bj: MyObject;

iObj: IMyObject;

begin

obj := Session(‘Some Value’);

iObj = Obj as IMyObject;

end;

Dim bj As MyObject = Session("Some Value")

Dim iObj As IMyObject = CType(obj, IMyObject)

MyObject obj = (MyObject)Session["Some Value"];
IMyObject iObj = obj;

MyObject obj = (MyObject)Session.getItem ("Some Value");
IMyObject iObj = obj;

类型转换

var

i: Integer;

s: String;

d: Double;

begin

i := 3;

s = i.ToString();

d := Double.Parse(s);

end;

Dim i As Integer = 3

Dim s As String = i.ToString()

Dim d As Double = Double.Parse(s):

int i = 3; 
String s = i.ToString(); 
double d = Double.Parse(s);

int i = 3; 
String s = Integer.valueof(i).toString();

double d = Double.valueof(s);

类别

delphi.net语法

vb.net 语法(语法不区分大小写)

c#.net 语法

java

If 结构

If Not (Request.QueryString = Null) then

begin

...

End;

If Not (Request.QueryString = Null)
 ... 
End If 
<!--[if !supportlinebreaknewline]-->
<!--[endif]-->

if (Request.QueryString != null)

{
... 
} 

if (Request.QueryString != null)

{
... 
} 

Case 结构

Case FirstName of

‘John’:

...

‘Paul’:

‘Ringo’:

End

Select (FirstName)
case "John" :

... 
<!--[if !supportlinebreaknewline]-->
<!--[endif]-->

case "Paul" :
...
case "Ringo" :
...
End Select

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

int flag = 1;

switch (flag){

case 1:

...

break;

case 2:

...

break;

}

For 循环

Var

I: Integer;

Begin

For I := 0 to 2 do

A[i] := ‘test’;

End;

Dim I As Integer

For I = 0 To 2
 a(I) = "test"
Next

for (int i=0; i<3; i++)

a(i) = "test";

for (int i=0; i<3; i++)

a[i] = "test";

While 循环

Var

I: Integer;

Begin

I := 0;

While i< 3 do

Begin

Console.WriteLen(i.ToString());

I := I + 1;

End;

End;

Dim I As Integer
I = 0

Do While I < 3

Console.WriteLine(i.ToString());

I = I + 1
Loop

int i = 0; 
while (i<3)

{
Console.WriteLine(i.ToString());
i += 1;

}

int i = 0; 
while (i<3)

{
System.out.println(i);
i += 1;

}

类别

delphi.net语法

vb.net 语法(语法不区分大小写)

c#.net 语法

java

类定义和继承

unit MySpace

interface

uses  System;

type

Foo = Class(Bar)

private

x: integer;

public

procedure Create; override; //构造函数

procedure Add(x: Integer);

function GetNum: Integer;

end;

implementation

procedure Foo.Create;

begin

inherited;  x := 4;

end;

procedure Foo.Add(x: Integer); begin

Self.x := Self.x + x;

end;

function Foo.GetNum: Integer; begin

Result := x;

end;

end;

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 

using System;

namespace MySpace

{

public class Foo : Bar

{
<!--[if !supportlinebreaknewline]-->
<!--[endif]-->

int x;

public Foo() {x = 4; } //构造函数
<!--[if !supportlinebreaknewline]-->
<!--[endif]-->

public void Add(int x) { this.x += x; }
<!--[if !supportlinebreaknewline]-->
<!--[endif]-->

public int GetNum() { return x; } 
<!--[if !supportlinebreaknewline]-->
<!--[endif]-->

}

}
// csc /out:librarycs.dll /t:library library.cs

import java.lang.*;

package MySpace;

public class Foo extends Bar{

private int x; //私有变量

public Foo() {x = 4; } //构造函数
<!--[if !supportlinebreaknewline]-->
<!--[endif]-->

public void Add(int x) { this.x += x; } //过程
<!--[if !supportlinebreaknewline]-->
<!--[endif]-->

public int getNum() { return x; } //函数
<!--[if !supportlinebreaknewline]-->
<!--[endif]-->

}

事件处理

procedure Button1OnClick(Sender: Object;E: EventArgs);

begin

...

end;

‘ByRef 在Pascal中对象是缺省参数传递方式

Sub Button1_Click(Sender As Object, E As EventArgs)

... 
End Sub

‘ByVal 在VB中对象是是缺省参数传递方式

void Button1_Click(Object sender, EventArgs E)

{
... 
} 
‘ByRef 在C#中对象是是缺省参数传递方式

jButton1.addMouseListener(new java.awt.event.MouseAdapter() {

public void mouseClicked(java.awt.event
.MouseEvent evt) {

Button1_Click(evt);

}

});

private void Button1_Click(java.awt. event
.MouseEvent evt) {

}

转载自网络,作者:张弓 2007/4/21于台中, 2008/4/18补充加入java

Pascal、VB、C#、Java四种语法对照表的更多相关文章

  1. Java 四种线程池newCachedThreadPool,newFixedThreadPool,newScheduledThreadPool,newSingleThreadExecutor

    介绍new Thread的弊端及Java四种线程池的使用,对Android同样适用.本文是基础篇,后面会分享下线程池一些高级功能. 1.new Thread的弊端执行一个异步任务你还只是如下new T ...

  2. Java四种线程池

    Java四种线程池newCachedThreadPool,newFixedThreadPool,newScheduledThreadPool,newSingleThreadExecutor 时间:20 ...

  3. Java四种引用包括强引用,软引用,弱引用,虚引用。

    Java四种引用包括强引用,软引用,弱引用,虚引用. 强引用: 只要引用存在,垃圾回收器永远不会回收Object obj = new Object();//可直接通过obj取得对应的对象 如obj.e ...

  4. Java四种引用--《深入理解Java虚拟机》学习笔记及个人理解(四)

    Java四种引用--<深入理解Java虚拟机>学习笔记及个人理解(四) 书上P65. StrongReference(强引用) 类似Object obj = new Object() 这类 ...

  5. (转载)new Thread的弊端及Java四种线程池的使用

    介绍new Thread的弊端及Java四种线程池的使用,对Android同样适用.本文是基础篇,后面会分享下线程池一些高级功能. 1.new Thread的弊端 执行一个异步任务你还只是如下new ...

  6. 不可访问内存 Java四种引用包括强引用,软引用,弱引用,虚引用

    小结: 1.不可访问内存是指一组没有任何可访问指针指向的由计算机程序进行动态分配的内存块. 2.垃圾收集器能决定是否一个对象还是可访问的:任何被确定不可访问的对象将会被释放. https://zh.w ...

  7. 线程池是什么?Java四种线程池的使用介绍

    使用线程池的好处有很多,比如节省系统资源的开销,节省创建和销毁线程的时间等,当我们需要处理的任务较多时,就可以使用线程池,可能还有很多用户不知道Java线程池如何使用?下面小编给大家分享Java四种线 ...

  8. java四种引用及在LeakCanery中应用

    java 四种引用 Java4种引用的级别由高到低依次为: StrongReference > SoftReference > WeakReference > PhantomRefe ...

  9. java四种对象引用类型

    java四种对象引用类型 对象的强.软.弱和虚引用 在JDK 1.2以前的版本中,若一个对象不被任何变量引用,那么程序就无法再使用这个对象.也就是说,只有对象处于可触及(reachable)状态,程序 ...

随机推荐

  1. LINUX SHELL条件判断

    算术运算的条件判断 [] [[]]: -eq -ne -lt -le -gt -ge (( )):><>=<== [root@monitor ~]# if (( 2 == 3) ...

  2. GNU bash实现机制与源代码简析

    http://www.cnblogs.com/napoleon_liu/archive/2011/04/01/2001886.html http://blog.csdn.net/ruglcc/arti ...

  3. 转--23种设计模式的搞笑解释(后续放逐一C++解释版本)

    创建型模式 1.FACTORY —追MM少不了请吃饭了,麦当劳的鸡翅和肯德基的鸡翅都是MM爱吃的东西,虽然口味有所不同,但不管你带MM去麦当劳或肯德基,只管向服务员说“来四个鸡翅”就行了.麦当劳和肯德 ...

  4. VMware:虚拟机磁盘空间不足怎么办

    前言: 虚拟机里一般我们用的虚拟磁盘,在电脑上是一个或多个文件,随着软件和数据的增多,有时也会提示磁盘空间不足. 那么,虚拟机磁盘空间不足如何处理呢?   一:调整磁盘分区大小; 若只是提示相应磁盘分 ...

  5. QSqlQueryModel的实例操作

    QSqlQueryModel类为SQL的结果集提供了一个只读的数据模型,下面我们先利用这个类进行一个最简单的操作. 我们新建Qt4 Gui Application工程,我这里工程名为queryMode ...

  6. mysql控制流程函数

    1.case语句 select case 2 when 1 then '男' when 2 then '女' else 'xoap' end as result; 2.if语句 select if(1 ...

  7. Java基础知识强化100:JVM 内存模型

    一. JVM内存模型总体架构图:  方法区和堆由所有线程共享,其他区域都是线程私有的 二. JVM内存模型的结构分析: 1. 类装载器(classLoader) 类装载器,它是在java虚拟机中用途是 ...

  8. java基础学习总结一(java语言发展历史、jdk的下载安装以及配置环境变量)

    最近一段时间计划复习一下java基础知识,使用的视频课程是尚学堂高淇老师的,上课过程中的心得体会直接总结一下,方便以后复习. 一:计算机语言的发展 1:机器语言,最原始的语言,主要有“01”构成,最早 ...

  9. hadoop的相关资料链接

    hadoop的资料整理博客 http://www.itpub.net/thread-1588509-1-1.html

  10. JUC全景图

    JUC 并发编程全景图如下: