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 = i.tostring();
double d = double.parse(s);
vb:
dim i as integer
dim s as string
dim d as double
i = 3
s = i.tostring()
d = cdbl(s)
15 类的声明和继承
c#:
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; }
}
}
vb:
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
16 声明类的主函数
c#:
using system;
public class consolecs {
public consolecs() {
console.writeline("object created");
}
public static void main (string[] args) {
console.writeline("hello world");
consolecs ccs = new consolecs();
}
}
vb
imports system
public class consolevb
public sub new()
mybase.new()
console.writeline("object created")
end sub
public shared sub main()
console.writeline("hello world")
dim cvb as consolevb
cvb = new consolevb()
end sub
end class
17 标准模块
c#
using system;
public class module {
public static void main (string[] args) {
console.writeline("hello world");
}
}
vb:
imports system
public module consolevb
public sub main()
console.writeline("hello world")
end sub
end module
本篇文章是由一篇英语的文章翻译来的,从这里面我们可以看到ms 为了统治web编程领域,花费了多大的心思!
他完全的重新定义了web编程的全部规范,使得web编程变的更加简单和功能强大!
现在在ms 的站点上已经可以 下载 asp+ 的解释器,但是太大!豆腐没有下载,哪位朋友有这个能力,下载下来,一读为快!
顺便给大家介绍一个学习 asp+ 的比较好的站点!只可惜 目前只有 英文的!我会在 适当 的时间里,给大家 翻译 尽可能 多的文章!
站点的 url是:
http://tutorial.superexpert.com/quickstart/aspplus/doc/langsupport.aspx
还有一个
http://www.15seconds.com也有关于 asp+ 的文章
Java Asp PHP .Net XML C/C++ CGI VB Jsp J2ee J2se J2me EJB Servlet Tomcat Resin Struts Weblogic Eclipse ANT GUI JMS Web servise IDEA Webphere Hibernate Spring Jboss Applet Swing Socket Javamail Perl Ajax P2P 安全 模式 框架 测试 开源 游戏
Windows XP Windows 2000 Windows 2003 Windows Me Windows 9.x Linux UNIX 注册表 操作系统 服务器 应用服务器