[Repost] ASP + grammar tutorial (1) preface

xiaoxiao2021-03-06  19

ASP now supports two languages ​​C # ("C Sharp"), Visual Basic, and JScript.

Based on habits, in the following language introduction, we use the practice and routines to develop web applications with VB and C # languages. If you want to get more information about .NET technology, please go to MS Sites to view about NGWS SDK!

In the list below, you can see a brief introduction to the syntax of these two languages

Variable reputation

C # syntax

INT X;

String S;

String S1, S2;

Object O;

Object obj = new object ();

Public String Name;

VB grammar

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 statement

C #:

Response.write ("Tofu");

VB:

Response.write ("Tofu")

3. Notes statement

// Tofu production, is a boutique

/ *

Tofu making

,

Both is boutique

* /

VB:

'Tofu production, all of the boutique

'Tofu making

',

'Is a boutique

4. Get the variable transferred by the 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. Declare attribute

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. array

C #

String [] a = new string [3];

a [0] = "1";

a [1] = "2";

a [2] = "3";

//Two-dimensional array

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 variable initialization

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; judgment statement (IF statement)

IF (Request.QueryString! = null) {

...

}

VB:

If not (Request.QueryString = NULL)

...

END IF

9. Branch statement (CASE statement)

C #:

Switch (firstname) {

Case "john":

...

Break;

Case "Paul":

...

Break;

Case "rinco":

...

Break;

}

VB:

SELECT (FirstName)

Case "john":

...

Case "Paul":

...

Case "rinco":

...

End SELECT

10 for loop statement

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 cycle

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 string connection

C #:

String S1;

String S2 = "Hello";

S2 = "world";

S1 = S2 "!!!";

VB:

DIM S1, S2 AS STRING

S2 = "Hello"

S2 & = "world"

S1 = S2 & "!!!"

Declaration event

C #:

Void MyButton_Click (Object Sender,

Eventargs e) {

...

}

VB:

Sub mybutton_click (sender as object,

E as eventargs)

...

End Sub

13 Declaration 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 data type conversion

C #

INT i = 3;

String s = i.to.tostring ();

Double d = double.parse (s);

VB:

DIM I as Integerdim S as String

DIM D As Double

i = 3

s = i.tostring ()

D = CDBL (s)

15 categories of statements and inheritance

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 statement of the main function

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 standard module

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

This article is translated by an English article. From this, we can see MS how much effort is spent in order to rule Web programming.

He completely redefines all the specifications for web programming, making web programming more simple and powerful!

Now you can download the ASP interpreter on the MS site, but too big! Tofu is not downloaded, which friend has this ability, download it, one read as fast!

By the way, introduce you to a better site to learn ASP ! Unfortunately, there is only English! I will translate as many articles as possible in the right time!

The URL of the site is:

Http://tutorial.supeRexpert.com/quickstart/aspplus/doc/langsupport.aspx has another

Http://www.15seconds.com also has an article about ASP

转载请注明原文地址:https://www.9cbs.com/read-41924.html

New Post(0)