home *** CD-ROM | disk | FTP | other *** search
-
- <!-- #include virtual="/quickstart/aspplus/include/header.inc" -->
-
- <h4>Language Support</h4>
-
- ASP+ currently offers built-in support for three languages, <b>C#</b> (pronounced "C Sharp"), <b>Visual Basic</b>, and
- <b>JScript</b>.
-
- <p>The exercises and code samples in this tutorial demonstrate the use of the VB and C# languages for building ASP+
- web applications. For information regarding the syntax of the other languages, refer to the complete documentation for the
- NGWS SDK.
-
- You may use the following table to understand the code samples in this tutorial and the differences between the two languages:
-
- <div style="margin:15,15,15,15">
-
- <p>
-
- <table class="table2" cellpadding=5 cellspacing=0 border=1>
- <tr><th>C# Syntax</th><th>VB Syntax</th></tr>
-
- <tr>
- <td colspan="2"><b>Variable Declarations</td>
- </tr>
- <tr>
- <td style="background-color:white">
- <div class="code"><xmp>
- int x;
- String s;
- String s1, s2;
- Object o;
- Object obj = new Object();
- public String name;
- </xmp></div>
- </td>
- <td style="background-color:white">
- <div class="code"><xmp>
- 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
- </xmp></div>
- </td>
- </tr>
-
-
- <tr>
- <td colspan="2"><b>Statements</td>
- </tr>
- <tr>
- <td style="background-color:white">
- <div class="code"><xmp>
- Response.Write("foo");
- </xmp></div>
- </td>
- <td style="background-color:white">
- <div class="code"><xmp>
- Response.Write("foo")
- </xmp></div>
- </td>
- </tr>
-
- <tr>
- <td colspan="2"><b>Comments</td>
- </tr>
- <tr>
- <td style="background-color:white">
- <div class="code"><xmp>
- // This is a comment
-
- /*
- This
- is
- a
- multi-line
- comment
- */
- </xmp></div>
- </td>
- <td style="background-color:white">
- <div class="code"><xmp>
- ' This is a comment
-
- ' This
- ' is
- ' a
- ' multi-line
- ' comment
- </xmp></div>
- </td>
- </tr>
-
- <tr>
- <td colspan="2"><b>Accessing Indexed Properties</td>
- </tr>
- <tr>
- <td style="background-color:white">
- <div class="code"><xmp>
- String s = Request.QueryString["Name"];
- String value = Request.Cookies["key"];
- </xmp></div>
- </td>
- <td style="background-color:white">
- <div class="code"><xmp>
- Dim s, value As String
- s = Request.QueryString("Name")
- value = Request.Cookies("Key").Value
-
- 'Note that default non-indexed properties
- 'must be explicitly named in VB
- </xmp></div>
- </td>
- </tr>
-
- <tr>
- <td colspan="2"><b>Declaring Simple Properties</td>
- </tr>
- <tr>
- <td style="background-color:white">
- <div class="code"><xmp>
- public String name {
-
- get {
- ...
- return ...;
- }
-
- set {
- ... = value;
- }
-
- }
- </xmp></div>
- </td>
- <td style="background-color:white">
- <div class="code"><xmp>
- Public Property Name As String
-
- Get
- ...
- Return ...;
- End Get
-
- Set
- ... = Value;
- End Set
-
- End Property
- </xmp></div>
- </td>
- </tr>
-
-
- <tr>
- <td colspan="2"><b>Arrays</td>
- </tr>
- <tr>
- <td style="background-color:white">
- <div class="code"><xmp>
- 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";
- </xmp></div>
- </td>
- <td style="background-color:white">
- <div class="code"><xmp>
- 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"
-
- ' Array of unspecified bounds (NA in C#)
-
- 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"
- </xmp></div>
- </td>
- </tr>
-
- <tr>
- <td colspan="2"><b>Initialization</td>
- </tr>
- <tr>
- <td style="background-color:white">
- <div class="code"><xmp>
- String s = "Hello World";
- int i = 1
- double[] a = { 3.00, 4.00, 5.00 };
- </xmp></div>
- </td>
- <td style="background-color:white">
- <div class="code"><xmp>
- Dim s As String = "Hello World"
- Dim i As Integer = 1
- Dim a() As Double = { 3.00, 4.00, 5.00 }
- </xmp></div>
- </td>
- </tr>
-
-
- <tr>
- <td colspan="2"><b>If Statements</td>
- </tr>
- <tr>
- <td style="background-color:white">
- <div class="code"><xmp>
- if (Request.QueryString != null) {
- ...
- }
- </xmp></div>
- </td>
- <td style="background-color:white">
- <div class="code"><xmp>
- If Not (Request.QueryString = Null)
- ...
- End If
- </xmp></div>
- </td>
- </tr>
-
-
- <tr>
- <td colspan="2"><b>Case Statements</td>
- </tr>
- <tr>
- <td style="background-color:white">
- <div class="code"><xmp>
- switch (FirstName) {
- case "John" :
- ...
- break;
- case "Paul" :
- ...
- break;
- case "Ringo" :
- ...
- break;
- }
- </xmp></div>
- </td>
- <td style="background-color:white">
- <div class="code"><xmp>
- Select (FirstName)
- case "John" :
- ...
- case "Paul" :
- ...
- case "Ringo" :
- ...
- End Select
- </xmp></div>
- </td>
- </tr>
-
-
- <tr>
- <td colspan="2"><b>For Loops</td>
- </tr>
- <tr>
- <td style="background-color:white">
- <div class="code"><xmp>
- for (int i=0; i<3; i++)
- a(i) = "test";
- </xmp></div>
- </td>
- <td style="background-color:white">
- <div class="code"><xmp>
- Dim I As Integer
- For I = 0 To 2
- a(I) = "test"
- Next
- </xmp></div>
- </td>
- </tr>
-
- <tr>
- <td colspan="2"><b>While Loops</td>
- </tr>
- <tr>
- <td style="background-color:white">
- <div class="code"><xmp>
- int i = 0;
- while (i<3) {
- Console.WriteLine(i.ToString());
- i += 1;
- }
- </xmp></div>
- </td>
- <td style="background-color:white">
- <div class="code"><xmp>
- Dim I As Integer
- I = 0
- Do While I < 3
- Console.WriteLine(I.ToString())
- I = I + 1
- Loop
- </xmp></div>
- </td>
- </tr>
-
-
-
-
- <tr>
- <td colspan="2"><b>String Concatenation</td>
- </tr>
- <tr>
- <td style="background-color:white">
- <div class="code"><xmp>
- String s1;
- String s2 = "hello";
- s2 += " world";
- s1 = s2 + " !!!";
- </xmp></div>
- </td>
- <td style="background-color:white">
- <div class="code"><xmp>
- Dim s1, s2 As String
- s2 = "hello"
- s2 &= " world"
- s1 = s2 & " !!!"
- </xmp></div>
- </td>
- </tr>
-
-
- <tr>
- <td colspan="2"><b>Event Handlers</td>
- </tr>
- <tr>
- <td style="background-color:white">
- <div class="code"><xmp>
- void MyButton_Click(Object sender,
- EventArgs E) {
- ...
- }
- </xmp></div>
- </td>
- <td style="background-color:white">
- <div class="code"><xmp>
- Sub MyButton_Click(Sender As Object,
- E As EventArgs)
- ...
- End Sub
-
- 'Note that ByVal is now the default
- 'for params in VB
- </xmp></div>
- </td>
- </tr>
-
- <tr>
- <td colspan="2"><b>Casting</td>
- </tr>
- <tr>
- <td style="background-color:white">
- <div class="code"><xmp>
- MyObject obj = (MyObject)Session["Some Value"];
- IMyObject iObj = obj
- </xmp></div>
- </td>
- <td style="background-color:white">
- <div class="code"><xmp>
- Dim bj As MyObject
- Dim iObj As IMyObject
- obj = Session("Some Value")
- iObj = CType(obj, IMyObject)
- </xmp></div>
- </td>
- </tr>
-
- <tr>
- <td colspan="2"><b>Conversion</td>
- </tr>
- <tr>
- <td style="background-color:white">
- <div class="code"><xmp>
- int i = 3;
- String s = i.ToString();
- double d = Double.Parse(s);
- </xmp></div>
- </td>
- <td style="background-color:white">
- <div class="code"><xmp>
- Dim i As Integer
- Dim s As String
- Dim d As Double
-
- i = 3
- s = i.ToString()
- d = CDbl(s)
-
- ' See also CDbl(...), CStr(...), ...
- </xmp></div>
- </td>
- </tr>
-
-
- <tr>
- <td colspan="2"><b>Class Definition w/ Inheritance</td>
- </tr>
- <tr>
- <td style="background-color:white">
- <div class="code"><xmp>
- 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; }
- }
-
- }
-
- // csc /out:librarycs.dll /t:library library.cs
- </xmp></div>
- </td>
- <td style="background-color:white">
- <div class="code"><xmp>
- 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
-
- ' vbc /out:libraryvb.dll /t:library library.vb
- </xmp></div>
- </td>
- </tr>
-
-
- <tr>
- <td colspan="2"><b>Class Definition w/ A Main method</td>
- </tr>
- <tr>
- <td style="background-color:white">
- <div class="code"><xmp>
- 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();
- }
-
- }
-
- // csc /out:consolecs.exe /t:exe console.cs
- </xmp></div>
- </td>
- <td style="background-color:white">
- <div class="code"><xmp>
- 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
-
- ' vbc /out:consolevb.exe /t:exe console.vb
- </xmp></div>
- </td>
- </tr>
-
-
-
- <tr>
- <td colspan="2"><b>Standard Module</td>
- </tr>
- <tr>
- <td style="background-color:white">
- <div class="code"><xmp>
- using System;
-
- public class Module {
-
- public static void Main (String[] args) {
- Console.WriteLine("Hello World");
- }
-
- }
- // csc /out:consolecs.exe /t:exe console.cs
- </xmp></div>
- </td>
- <td style="background-color:white">
- <div class="code"><xmp>
- Imports System
-
- Public Module ConsoleVB
-
- Public Sub Main()
- Console.WriteLine("Hello World")
- End Sub
-
- End Module
-
- ' vbc /out:consolevb.exe /t:exe console.vb
- </xmp></div>
- </td>
- </tr>
-
- </table>
-
- <p>
-
- </div>
-
- <!-- #include virtual="/quickstart/aspplus/include/footer.inc" -->