Introduction to asp+ syntax (1)
Author:Eve Cole
Update Time:2009-05-30 19:54:20
*/ASP+ now supports two languages: C# ("C Sharp" for short), Visual Basic, and JScript.
Based on habits, in the following language introduction, the exercises and routines we use use VB and C# languages to develop Web applications. If you want to get detailed information about .Net technology, please go to the MS website to view the NGWS SDK!
In the list below you can see a brief introduction to the syntax of both languages
1. Variable declaration
C# syntax
int x;
String s;
String s1, s2;
Object o;
Object obj = new Object();
public String name;
VB syntax
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 is excellent
/*
tofu making,
All are fine products
*/
VB:
'The tofu production is excellent.
' Tofu making
',
'They are all fine products
4. Get the variables passed 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 attributes
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"
7Variable 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
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 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 concatenation
C#:
String s1;
String s2 = "hello";
s2 += "world";
s1 = s2 + "!!!";
VB:
Dim s1, s2 As String
s2 = "hello"
s2 &= "world"
s1 = s2 & " !!!"
declare event
C#:
void MyButton_Click(Object sender,
EventArgs E) {
...
}
VB:
Sub MyButton_Click(Sender As Object,
E As EventArgs)
...
End Sub
13 Declare 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.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 Class declaration 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
NamespaceMySpace
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 Declare the main function of the class
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 modules
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 from an English article. From this we can see how much effort MS has put into dominating the field of Web programming!
He completely redefined all the specifications of Web programming, making Web programming simpler and more powerful!
Now you can download the asp+ interpreter from the MS website, but it is too big! Tofu has not been downloaded. Which friend has this ability? Download it and read it quickly!
By the way, I would like to introduce to you a better site for learning Asp+! It’s a pity that it’s only available in English at the moment! I will give you the translation as much as possible at the appropriate time
Many articles!
The URL of the site is:
http://tutorial.superexpert.com/quickstart/aspplus/doc/langsupport.aspx
There is another
http://www.15seconds.com also has articles about Asp+