Introduction to Asp+ grammar (i)

Source: Internet
Author: User
Tags array object case statement end integer string variable tostring
asp+| Grammar/*
Article Source: http://www.aspCool.com reproduced Please specify everywhere, thank you!
*/asp+ now supports two languages C # (referred to as "C Sharp"), Visual Basic, and JScript.
Based on custom, in the following language introduction, we use the practice and routines in VB and C # language to develop Web applications. If you want more information about. NET technology, please go to MS's site to see About NGWS sdk!
In the following list, you can see a brief introduction to the syntax of both languages
1. 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 statements
C#:
Response.Write ("tofu");
Vb:
Response.Write ("Tofu")

3. Comment Statement
Tofu production, are fine
/*
Tofu Production

It's all fine.
*/

Vb:
' Tofu production, are fine
' Tofu Making
',
' It's all fine.
4. Get the URL pass variable
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. Declaring properties
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 "Ringo":
...
Break
}
Vb:
Select (FirstName)
Case "John":
...
Case "Paul":
...
Case "Ringo":
...
End Select

A 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

One while loop
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 & "!!!"


declaring events
C#:
void MyButton_Click (Object sender,
EventArgs E) {
...
}
Vb:
Sub MyButton_Click (Sender as Object,
E as EventArgs)
...
End Sub


13 Declaring 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 Conversions
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 declaration and inheritance of classes
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

[1] [2] Next page



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.