Dim x As Integer
Dim s As String
Dim ss As String
Dim oImplicitly Object
Dim obj As New Object()
Public name As Stringvar x : int;
var s : String;
var s: String s : String;
var o;
var obj : Object = new Object();
var name : String;
Response
Write( foo );
) This is a comment
)// This is a comment
)/*
This
is
a
multiline
comment
*/
Public Property Name As String
Get
Return
End GetSet
= Value
End SetEnd Property
function get name() : String {
return;
}function set name(value : String) {
= value;
}
Default Indexed Property
Public Default ReadOnly Property DefaultProperty(Name As String) As String
Get
Return CStr(lookuptable(name))
End Get
End Property
Dim s
value As String
s = RequestQueryString( Name )
value = RequestCookies( Key ) Value
Note that default non indexed properties must be explicitly named in VB var s : String = Request
QueryString( Name );
var value : String = RequestCookies( key );
Declare the Enumeration
Public Enum MessageSizeSmall =
Medium =
Large =
End Enum
Create a Field or Property
Public MsgSize As MessageSize
Assign to the property using the Enumeration values
MsgSize = small// Declare the Enumeration
public enum MessageSize {Small =
Medium =
Large =
}// Create a Field or Property
public var msgsize:MessageSize;// Assign to the property using the Enumeration values
msgsize = Small;
Declare a void return function
Sub VoidFunction()
End Sub
Declare a function that returns a value
Function StringFunction() As String
Return CStr(val)
End Function
Declare a function that takes and returns values
Function ParmFunction(a As Stringb As String) As String
Return CStr(A & B)
End Function
Use the Functions
VoidFunction()
Dim sAs String = StringFunction()
Dim sAs String = ParmFunction( Hello World! ) // Declare a void return function
function voidfunction() : void {
}// Declare a function that returns a value
function stringfunction() : String {
return String(val);
}// Declare a function that takes and returns values
function parmfunction(a:Stringb:String) : String {
return String(a + b);
}// Use the Functions
voidfunction();
var s:String = stringfunction();
var s:String = parmfunction( Hello World! );
Dim a(
) As String
a() =
a() =
a() = Dim a(
) As String
a() =
a() =
a() =
var a : String[] = new String[];
a[] = ;
a[] = ;
a[] = ; var a : String[][] = new String[
][ ];
a[][ ] = ;
a[][ ] = ;
a[][ ] = ;
Dim s As String =Hello World
Dim i As Integer =
Dim a() As Double = {}
var s : String =Hello World ;
var i : int =;
var a : double[] = [];
if (Request
QueryString != null) {
}If Not (Request
QueryString = Nothing)
End Ifif (Request
QueryString != null) {
}
switch (FirstName) {
caseJohn :
break;
casePaul :
break;
caseRingo :
break;
default:
break;
}Select Case FirstName
CaseJohn
CasePaul
CaseRingo
Case Else
End Selectswitch (FirstName) {
caseJohn :
break;
casePaul :
break;
caseRingo :
break;
default:
break;
}
for (int i=
; i< ; i++)
a(i) =test ; Dim I As Integer
For I =To
a(I) =test
Nextfor (var i : int =
; i < ; i++)
a[i] =test ;
int i =
;
while (i<) {
ConsoleWriteLine(i ToString());
i +=;
}Dim I As Integer
I =
Do While I <
ConsoleWriteLine(I ToString())
I +=
Loopvar i : int =
;
while (i <) {
ConsoleWriteLine(i);
i +=;
}
try {
// Code that throws exceptions
} catch(OverflowException e) {
// Catch a specific exception
} catch(Exception e) {
// Catch the generic exceptions
} finally {
// Execute some cleanup code
}Try
Code that throws exceptions
Catch E As OverflowException
Catch a specific exception
Catch E As Exception
Catch the generic exceptions
Finally
Execute some cleanup code
End Trytry {
// Code that throws exceptions
} catch(e:OverflowException) {
// Catch a specific exception
} catch(e:Exception) {
// Catch the generic exceptions
} finally {
// Execute some cleanup code
}
// Using Strings
String s;
String s= hello ;
s+= world ;
s= s + !!! ; // Using StringBuilder class for performance
StringBuilder s= new StringBuilder();
sAppend( hello );
sAppend( world );
sAppend( !!! );
Using Strings
Dim ss As String
s= hello
s&= world
s= s & !!!
Using StringBuilder class for performance
Dim sAs New StringBuilder()
sAppend( hello )
sAppend( world )
sAppend( !!! ) // Using Strings
var s: String;
var s: String = hello ;
s+= world ;
s= s + !!! ; // Using StringBuilder class for performance
var s:StringBuilder = new StringBuilder();
sAppend( hello );
sAppend( world );
sAppend( !!! );
void MyButton_Click(Object sender
EventArgs E) {
}Sub MyButton_Click(Sender As Object
E As EventArgs)
End Subfunction MyButton_Click(sender : Object
E : EventArgs) {
}
// Create a public event
public event EventHandler MyEvent;// Create a method for firing the event
protected void OnMyEvent(EventArgs e) {
MyEvent(thise);
}
Create a public event
Public Event MyEvent(Sender as ObjectE as EventArgs)
Create a method for firing the event
Protected Sub OnMyEvent(E As EventArgs)
RaiseEvent MyEvent(MeE)
End SubJScript does not support the creation of events
JScript can only
consume events by declaring event handler delegates and adding those
delegates to the events of another control
Control
Change += new EventHandler(this ChangeEventHandler);
ControlChange = new EventHandler(this ChangeEventHandler); AddHandler Control
Change AddressOf Me ChangeEventHandler
RemoveHandler ControlChange AddressOf Me ChangeEventHandler Control
Change += this ChangeEventHandler;
ControlChange = this ChangeEventHandler;
MyObject obj = (MyObject)Session[
Some Value ];
IMyObject iObj = obj;Dim obj As MyObject
Dim iObj As IMyObject
obj = Session(Some Value )
iObj = CType(objIMyObject) var obj : MyObject = MyObject(Session(
Some Value ));
var iObj : IMyObject = obj;
int i =
;
String s = iToString();
double d = DoubleParse(s); Dim i As Integer
Dim s As String
Dim d As Doublei =
s = iToString()
d = CDbl(s)
See also CDbl( ) CStr( ) var i : int =
;
var s : String = iToString();
var d : double = Number(s);
using System;
namespace MySpace {
public class Foo : Bar {
int x;
public Foo() { x =
; }
public void Add(int x) { thisx += x; }
override public int GetNum() { return x; }
}}
// csc /out:librarycs
dll /t:library
// librarycs
Imports SystemNamespace MySpace
Public Class Foo : Inherits Bar
Dim x As Integer
Public Sub New()
MyBaseNew()
x =
End SubPublic Sub Add(x As Integer)
Mex = Me x + x
End SubOverrides Public Function GetNum() As Integer
Return x
End FunctionEnd Class
End Namespace
vbc /out:libraryvb dll /t:library library vb
import System;package MySpace {
class Foo extends Bar {
private var x : int;
function Foo() { x =
; }
function Add(x : int) { thisx += x; }
override function GetNum() : int { return x; }
}}
// jsc /out:libraryjs
dll library js
public class MyClass : IEnumerable {
IEnumerator IEnumerable
GetEnumerator() {
}
}Public Class MyClass : Implements IEnumerable
Function IEnumerable_GetEnumerator() As IEnumerator Implements IEnumerable
GetEnumerator
End Function
End Class
public class MyClass implements IEnumerable {
function IEnumerable
GetEnumerator() : IEnumerator {
}
}
using System;
public class ConsoleCS {
public ConsoleCS() {
ConsoleWriteLine( Object Created );
}public static void Main (String[] args) {
ConsoleWriteLine( Hello World );
ConsoleCS ccs = new ConsoleCS();
}}
// csc /out:consolecs
exe /t:exe console cs Imports System
Public Class ConsoleVB
Public Sub New()
MyBaseNew()
ConsoleWriteLine( Object Created )
End SubPublic Shared Sub Main()
ConsoleWriteLine( Hello World )
Dim cvb As New ConsoleVB
End SubEnd Class
vbc /out:consolevb exe /t:exe console vb class ConsoleCS {
function ConsoleCS() {
print(Object Created );
}static function Main (args : String[]) {
print(Hello World );
var ccs : ConsoleCS = new ConsoleCS();
}
}// jsc /out:consolejs
exe /exe console js
using System;
public class Module {
public static void Main (String[] args) {
ConsoleWriteLine( Hello World );
}}
// csc /out:consolecsexe /t:exe console cs Imports System
Public Module ConsoleVB
Public Sub Main()
ConsoleWriteLine( Hello World )
End SubEnd Module
vbc /out:consolevb exe /t:exe console vb print(
Hello World ); // jsc /out:consolejs
exe /exe console js
From:http://tw.wingwit.com/Article/program/net/201311/14535.html