C # & VB brief introduction to two language syntax

xiaoxiao2021-03-06  56

C # & VB brief introduction to two language syntax

Www.chinacs.net2001-6-2 12:45:00 Chinese

C # technology station

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 ("Chinese C # Technology Station"); VB: Response.write ("Chinese C # Technology Station")

3. Note Strategy // Chinese C # Technology Station / * Welcome Access, Chinese C # Technology Station * /

VB: 'Chinese C # Technology Station

4. Get the variable passing of 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. Declaration attribute C #: public string name {

Get {... returnit ...;

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"; // 2D 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) = "1" A (1,0) = "2" a (2, 0) = "3"

DIM A () AS String A (0) = "1" a (1,0) = "2" A (2, 0) = "3"

DIM A (,) AS STRING A (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) ... Endiff

9. Branch statement (CASE statement) C #: switch (firstname) {CASE "john": ... Break; Case "Paul": ... Break; Case "Ringo": ... Break;} VB: SELECT Firstname): 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 & "!!!"

Declare event C #: void mybutton_click (object sender, evenetargs e) {...} VB: Sub MyButton_Click (Sender As Object, E AS EventArgs) ... End Sub

13 Statement 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 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 () {returnix}}

}

VB: imports system

Namespace MySpace

Public Class Foo: Inherits Bardim x as inherit

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 returnx x end function

END CLASS

End Namespace

16 Starial Master 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

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

New Post(0)