asp+语法教程(一)前言

北京Ts卡丝娜

北京Ts卡丝娜

2016-01-29 19:12

asp+语法教程(一)前言,asp+语法教程(一)前言
  ASP+ 现在支持两种语言C# (简称 "C Sharp"), Visual Basic, and JScript.
基于习惯,在以下的语言介绍中,我们采用的练习和例程采用VB和C#语言来开发Web应用程序.如果想要得到关于.Net技术的详细资料,请去MS的站点 查看关于 NGWS SDK!
在下面的列表中,你可以看到关于这两种语言的语法的简要介绍
1.变量声名
C# 语法
int x;
String s;
String s1, s2;
Object o;
Object obj = new Object();
public String name;
VB语法
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


2语句
C#:
Response.Write("豆腐");
VB:
Response.Write("豆腐")

3.注释语句
//豆腐制作,都是精品
/*
豆腐制作

都是精品
*/

VB:
'豆腐制作,都是精品
' 豆腐制作
',
'都是精品
4.获得URL 传递的变量
C#:
String s = Request.QueryString["Name"];
String value = Request.Cookies["key"];
VB:
Dim s, value As String
s = Request.QueryString("Name")
value = Request.Cookies("Key").Value
5.声明属性
C#:
public String name {

get {
...
return ...;
}

set {
... = value;
}

}

VB:
Public Property Name As String

Get
...
Return ...;
End Get

Set
... = Value;
End Set

End Property
6.数组
C#
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";
VB:
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() 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"


7变量初始化
C#:
String s = "Hello World";
int i = 1
double[] a = { 3.00, 4.00, 5.00 };
VB:
Dim s As String = "Hello World"
Dim i As Integer = 1
Dim a() As Double = { 3.00, 4.00, 5.00 }

8;判断语句(If 语句)
if (Request.QueryString != null) {
...
}

VB:
If Not (Request.QueryString = Null)
...
End If

9.分支语句(case 语句)
C#:
switch (FirstName) {
case "John" :
...
break;
case "Paul" :
...
break;
case "Ringo" :
...
break;
}
VB:
Select (FirstName)
case "John" :
...
case "Paul" :
...
case "Ringo" :
...
End Select

10 For循环语句
C#
for (int i=0; i<3; i++)
a(i) = "test";
VB:
Dim I As Integer
For I = 0 To 2
a(I) = "test"
Next

11 While 循环
C#:
int i = 0;
while (i<3) {
Console.WriteLine(i.ToString());
i += 1;
}
VB:
Dim I As Integer
I = 0
Do While I < 3
Console.WriteLine(I.ToString())
I = I + 1
Loop
12 字符串连接
C#:
String s1;
String s2 = "hello";
s2 += " world";
s1 = s2 + " !!!";
VB:
Dim s1, s2 As String
s2 = "hello"
s2 &= " world"
s1 = s2 & " !!!"


声明事件
C#:
void MyButton_Click(Object sender,
EventArgs E) {
...
}
VB:
Sub MyButton_Click(Sender As Object,
E As EventArgs)
...
End Sub


13 声明Object
C#
MyObject obj = (MyObject)Session["Some Value"];
IMyObject iObj = obj
VB:
Dim bj As MyObject
Dim iObj As IMyObject
obj = Session("Some Value")
iObj = CType(obj, IMyObject)


14 数据类型转换
C#
int i = 3;
String s =
展开更多 50%)
分享

猜你喜欢

asp+语法教程(一)前言

ASP
asp+语法教程(一)前言

asp+语法介绍(一)

ASP
asp+语法介绍(一)

s8lol主宰符文怎么配

英雄联盟 网络游戏
s8lol主宰符文怎么配

asp+语法教程(二)书写我们的第一个asp+文件

ASP
asp+语法教程(二)书写我们的第一个asp+文件

asp+语法教程(六)数据库篇

ASP
asp+语法教程(六)数据库篇

lol偷钱流符文搭配推荐

英雄联盟 网络游戏
lol偷钱流符文搭配推荐

asp+语法教程(三)asp+的服务器端编程初步

ASP
asp+语法教程(三)asp+的服务器端编程初步

ASP+配置 — ASP+配置概念(一)

ASP
ASP+配置 — ASP+配置概念(一)

lolAD刺客新符文搭配推荐

英雄联盟
lolAD刺客新符文搭配推荐

Photoshop教程:红木像框的制作过程

Photoshop教程:红木像框的制作过程

ASP 3.0高级编程(十)

ASP 3.0高级编程(十)
下拉加载更多内容 ↓