📄 0049.htm
字号:
<html>
<head>
<title>新时代软件教程:操作系统 主页制作 服务器 设计软件 网络技术 编程语言 文字编辑</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<style>
<!--
body, table {font-size: 9pt; font-family: 宋体}
a {text-decoration:none}
a:hover {color: red;text-decoration:underline}
.1 {background-color: rgb(245,245,245)}
-->
</style>
</head>
<p align="center"><script src="../../1.js"></script></a>
<p align="center"><big><strong>ASP+ 支持的 C# 和 VB 语法对照表</strong></big></p>
<div align="right">---摘自《ChinaAsp网络》(文/讨饭猫)</div><SPAN class=smallFont><SPAN class=smallFont>
ASP+内置支持3种语言:C#,Visual Basic(注意不是VBScript),JScript。下面列出一个简单的C#和VB语法对照表,看看你到底喜欢那个?<table class=ubb cellspacing=0><tr><td class=ubb><br>
<b>C# 语法</b></td><td class=ubb><b><br>
VB 语法</b></td></tr><tr><td class=ubb><b><br>
定义变量</b></td></tr><tr><td class=ubb><br>
int x; <br>
String s; <br>
String s1, s2; <br>
Object o; <br>
Object obj = new Object(); <br>
public String name; </td><td class=ubb><br>
Dim x As Integer <br>
Dim s As String <br>
Dim s1, s2 As String <br>
Dim o 'Implicitly Object <br>
Dim obj As New Object() <br>
Public name As String </td></tr><tr><td class=ubb><b><br>
输出内容</b></td></tr><tr><td class=ubb><br>
Response.Write("foo"); </td><td class=ubb><br>
Response.Write("foo") </td></tr><tr><td class=ubb><b><br>
注释</b></td></tr><tr><td class=ubb><br>
// This is a comment <br>
/* This is a multi-line comment */ </td><td class=ubb><br>
' This is a comment<br>
' This <br>
' is<br>
' a <br>
' multi-line<br>
' comment </td></tr><tr><td class=ubb><b><br>
读取数据集合数组</b></td></tr><tr><td class=ubb><br>
String s = Request.QueryString["Name"]; <br>
String value = Request.Cookies["key"]; </td><td class=ubb><br>
Dim s, value As String <br>
s = Request.QueryString("Name") <br>
value = Request.Cookies("Key").Value <br>
'Note that default non-indexed properties<br>
'must be explicitly named in VB </td></tr><tr><td class=ubb><b><br>
定义简单数据集</b></td></tr><tr><td class=ubb><br>
public String name { <br>
get {<br>
... <br>
return ...; <br>
} <br>
set {<br>
... = value; <br>
}<br>
} </td><td class=ubb><br>
Public Property Name As String<br>
Get <br>
... <br>
Return<br>
...; <br>
End Get<br>
Set<br>
... = Value; <br>
End Set <br>
End Property </td></tr><tr><td class=ubb><b><br>
数组</b></td></tr><tr><td class=ubb><br>
String[] a = new String[3]; <br>
a[0] = "1"; <br>
a[1] = "2"; <br>
a[2] = "3<br>
String[][] a = new String[3][3]; <br>
a[0][0] = "1"; <br>
a[1][0] = "2"; <br>
a[2][0] = "3"; </td><td class=ubb><br>
Dim a(3) As String <br>
a(0) = "1" <br>
a(1) = "2" <br>
a(2) = "3" <br>
Dim a(3,3) As String <br>
a(0,0) = "1" <br>
a(1,0) = "2" <br>
a(2,0) = "3"<br>
' Array of unspecified bounds (NA in C#) <br>
Dim a() As String <br>
a(0,0) = "1" <br>
a(1,0) = "2" <br>
a(2,0) = "3" <br>
Dim a(,) As String <br>
a(0,0) = "1" <br>
a(1,0) = "2" <br>
a(2,0) = "3" </td></tr><tr><td class=ubb><b><br>
初始化变量</b></td></tr><tr><td class=ubb><br>
String s = "Hello World"; <br>
int i = 1 <br>
double[] a = { 3.00, 4.00, 5.00 }; </td><td class=ubb><br>
Dim s As String = "Hello World" <br>
Dim i As Integer = 1 <br>
Dim a() As Double = { 3.00, 4.00, 5.00 } </td></tr><tr><td class=ubb><b><br>
If 结构</b></td></tr><tr><td class=ubb><br>
if (Request.QueryString != null) {<br>
... <br>
} </td><td class=ubb><br>
If Not (Request.QueryString = Null)<br>
... <br>
End If </td></tr><tr><td class=ubb><b><br>
Case 结构</b></td></tr><tr><td class=ubb><br>
switch (FirstName){<br>
case "John" :<br>
... <br>
break; <br>
case "Paul" : <br>
... <br>
break; <br>
case "Ringo" : <br>
... <br>
break; <br>
} </td><td class=ubb><br>
Select (FirstName)<br>
case "John" :<br>
... <br>
case "Paul" :<br>
...<br>
case "Ringo" :<br>
...<br>
End Select </td></tr><tr><td class=ubb><b><br>
For 循环</b></td></tr><tr><td class=ubb><br>
for (int i=0; i<3; i++)<br>
a(i) = "test"; </td><td class=ubb><br>
Dim I As Integer<br>
For I = 0 To 2<br>
a(I) = "test"<br>
Next </td></tr><tr><td class=ubb><b><br>
While 循环</b></td></tr><tr><td class=ubb><br>
int i = 0; <br>
while (i<3) {<br>
Console.WriteLine(i.ToString());<br>
i += 1;<br>
} </td><td class=ubb><br>
Dim I As Integer<br>
I = 0 Do While I </td></tr><tr><td class=ubb><b><br>
字符串操作</b></td></tr><tr><td class=ubb><br>
String s1; <br>
String s2 = "hello"; <br>
s2 += " world"; <br>
s1 = s2 + " !!!"; </td><td class=ubb><br>
Dim s1, s2 As String <br>
s2 = "hello" <br>
s2 &= " world" <br>
s1 = s2 & " !!!" </td></tr><tr><td class=ubb><b><br>
事件处理</b></td></tr><tr><td class=ubb><br>
void MyButton_Click(Object sender, EventArgs E) {<br>
... <br>
} </td><td class=ubb><br>
Sub MyButton_Click(Sender As Object, E As EventArgs)<br>
... <br>
End Sub<br>
注意 ByVal 在VB中是省缺参数 </td></tr><tr><td class=ubb><b><br>
对象操作</b></td></tr><tr><td class=ubb><br>
MyObject obj = (MyObject)Session["Some Value"];<br>
IMyObject iObj = obj </td><td class=ubb><br>
Dim bj As MyObject <br>
Dim iObj As IMyObject <br>
obj = Session("Some Value") <br>
iObj = CType(obj, IMyObject) </td></tr><tr><td class=ubb><b><br>
类型转换</b></td></tr><tr><td class=ubb><br>
int i = 3; <br>
String s = i.ToString(); <br>
double d = Double.Parse(s); </td><td class=ubb><br>
Dim i As Integer <br>
Dim s As String <br>
Dim d As Double <br>
i = 3 <br>
s = i.ToString() <br>
d = CDbl(s)<br>
' 参见 CDbl(...), CStr(...), ... </td></tr><tr><td class=ubb><b><br>
类定义和继承</b></td></tr><tr><td class=ubb><br>
using System; <br>
namespace MySpace {<br>
public class Foo : Bar {<br>
int x; <br>
public Foo() {x = 4; } <br>
public void Add(int x) { this.x += x; } <br>
public int GetNum() { return x; } <br>
} <br>
}<br>
// csc /out:librarycs.dll /t:library library.cs </td><td class=ubb><br>
Imports System <br>
Namespace MySpace <br>
Public Class Foo : Inherits Bar <br>
Dim x As Integer <br>
<br>
Public Sub New() <br>
MyBase.New() <br>
x = 4 <br>
End Sub <br>
Public Sub Add(x As Integer) <br>
Me.x = Me.x + x <br>
End Sub <br>
Public Function GetNum() As Integer <br>
Return x <br>
End Function <br>
End Class <br>
End Namespace <br>
' vbc /out:libraryvb.dll /t:library library.vb </td></tr></table><br>
(也许是多年来用惯了C的缘故,一直喜欢C那种简练,个性化的风格,文字和符号混合使用,可以让眼睛迅速找到关键所在,避免视线被淹没在复杂的字符串中,所以即使在 ASP 时代,也是坚持使用风格类似的 JScript,现在终于……hehehe…..-讨饭猫)<br>
</table>
<p align="center"><script src="../../2.js"></script></a>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -