asp+语法介绍(一)

分类: asp   出处:iocblog整理  更新时间:2008-10-09   添加到收藏  

*/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 & " !!!"

[1] [2] 下一页