asp+语法介绍(一)

浏览:25日期:2022-11-24
*/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 IntegerDim s As StringDim s1, s2 As StringDim o 'Implicitly ObjectDim obj As New Object()Public name As String2语句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 Strings = 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 SetEnd Property6.数组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 = 1double[] a =;;{ 3.00, 4.00, 5.00 };VB:Dim s As String = "Hello World"Dim i As Integer = 1Dim a() As Double = { 3.00, 4.00, 5.00 }8;判断语句(If 语句)if (Request.QueryString != null) {;;...}VB:If Not (Request.QueryString = Null);;...End If9.分支语句(case 语句) C#:switch (FirstName) {;;case "John" :;;;;...;;;;break;;;case "Paul" :;;;;...;;;;break;;;case "Ringo" :;;;;...;;;;break;}VB:Select (FirstName);;case "John" :;;;;...;;case "Paul" :;;;;...;;case "Ringo" :;;;;...End Select10 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";;Next11 While 循环C#:int i = 0;while (i<3) {;;Console.WriteLine(i.ToString());;;i += 1;}VB:Dim I As IntegerI = 0Do While I < 3;;Console.WriteLine(I.ToString());;I = I + 1Loop12 字符串连接C#:String s1;String s2 = "hello";s2 += " world";s1 = s2 + " !!!";VB:Dim s1, s2 As Strings2 = "hello"s2 &= " world"s1 = s2 & " !!!"声明事件C#:void MyButton_Click(Object sender, ;;;;EventArgs E) {...}VB:Sub MyButton_Click(Sender As Object, ;;;;E As EventArgs)...End Sub13 声明ObjectC#MyObject obj = (MyObject)Session["Some Value"];IMyObject iObj = objVB:Dim bj As MyObjectDim iObj As IMyObjectobj = 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 IntegerDim s As StringDim d As Doublei = 3s = 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 SystemNamespace 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 ClassEnd Namespace16 声明类的主函数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();;;}}VBImports SystemPublic 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 SubEnd Class17 标准模块C#using System;public class Module {public static void Main (String[] args) {;;Console.WriteLine("Hello World");}}VB:Imports SystemPublic Module ConsoleVB;;Public Sub Main();;;;Console.WriteLine("Hello World");;End SubEnd Module本篇文章是由一篇英语的文章翻译来的,从这里面我们可以看到MS 为了统治Web编程领域,花费了多大的心思!他完全的重新定义了Web编程的全部规范,使得Web编程变的更加简单和功能强大!现在在MS 的站点上已经可以 下载 asp+ 的解释器,但是太大!豆腐没有下载,哪位朋友有这个能力,下载下来,一读为快!顺便给大家介绍一个学习 Asp+ 的比较好的站点!只可惜 目前只有;;英文的!我会在 适当 的时间里,给大家;;翻译;;尽可能;;多的文章!站点的 URl是:http://tutorial.superexpert.com/quickstart/aspplus/doc/langsupport.aspx还有一个http://www.15seconds.com也有关于 Asp+ 的文章
相关文章: