• <ruby id="5koa6"></ruby>
    <ruby id="5koa6"><option id="5koa6"><thead id="5koa6"></thead></option></ruby>

    <progress id="5koa6"></progress>

  • <strong id="5koa6"></strong>
    • 軟件測試技術
    • 軟件測試博客
    • 軟件測試視頻
    • 開源軟件測試技術
    • 軟件測試論壇
    • 軟件測試沙龍
    • 軟件測試資料下載
    • 軟件測試雜志
    • 軟件測試人才招聘
      暫時沒有公告

    字號: | 推薦給好友 上一篇 | 下一篇

    ASP.NET入門—語法介紹

    發布: 2008-4-07 10:55 | 作者: jiaying | 來源: 希賽網 | 查看: 50次 | 進入軟件測試論壇討論

    領測軟件測試網  1.聲明變量

    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

    var x : int;
    var s : String;
    var s1 : String, s2 : String;
    var o;
    var obj : Object = new Object();
    var name : String;


        2.語句輸出

    Response.Write("foo");


        3.代碼注釋

    1)' This is a comment

    2)// This is a comment

    3)/*
      This
      is
      a
      multiline
      comment
     */


        4.聲明簡單屬性

    Public Property Name As String

      Get
        ...
        Return ...
      End Get

      Set
        ... = Value
      End Set

    End Property

    function get name() : String {
        ...
        return ...;
    }

    function set name(value : String) {
        ... = value;
    }


        5.聲明索引屬性

    ' Default Indexed Property
    Public Default ReadOnly Property DefaultProperty(Name As String) As String
        Get
            Return CStr(lookuptable(name))
        End Get
    End Property


        6.訪問索引屬性

    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

    var s : String = Request.QueryString("Name");
    var value : String = Request.Cookies("key");


        7.聲明和使用枚舉

    ' Declare the Enumeration
    Public Enum MessageSize

        Small = 0
        Medium = 1
        Large = 2
    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 = 0,
        Medium = 1,
        Large = 2
    }

    // Create a Field or Property
    public var msgsize:MessageSize;

    // Assign to the property using the Enumeration values
    msgsize = Small;


        8.聲明和使用方法

    ' 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 String, b As String) As String
     ...
        Return CStr(A & B)
    End Function

    ' Use the Functions
    VoidFunction()
    Dim s1 As String = StringFunction()
    Dim s2 As 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:String, b:String) : String {
     ...
        return String(a + b);
    }

    // Use the Functions
    voidfunction();
    var s1:String = stringfunction();
    var s2:String = parmfunction("Hello", "World!");


        9.數組

     Dim a(2) As String
        a(0) = "1"
        a(1) = "2"
        a(2) = "3"

        Dim a(2,2) As String
        a(0,0) = "1"
        a(1,0) = "2"
        a(2,0) = "3"


        var a : String[] = new String[3];
        a[0] = "1";
        a[1] = "2";
        a[2] = "3";

        var a : String[][] = new String[3][3];
        a[0][0] = "1";
        a[1][0] = "2";
        a[2][0] = "3";


        10.初始化


    Dim s As String = "Hello World"
    Dim i As Integer = 1
    Dim a() As Double = { 3.00, 4.00, 5.00 }


    var s : String = "Hello World";
    var i : int = 1;
    var a : double[] = [ 3.00, 4.00, 5.00 ];


        11.If 語句

    if (Request.QueryString != null) {
      ...
    }

    If Not (Request.QueryString = Nothing)
      ...
    End If

    if (Request.QueryString != null) {
      ...
    }
     

        12.Case 語句

    switch (FirstName) {
      case "John" :
        ...
        break;
      case "Paul" :
        ...
        break;
      case "Ringo" :
        ...
        break;
      default:
        ...
        break;
    }

    Select Case FirstName
      Case "John"
        ...
      Case "Paul"
        ...
      Case "Ringo"
        ...
      Case Else
        ...
    End Select

    switch (FirstName) {
      case "John" :
        ...
        break;
      case "Paul" :
        ...
        break;
      case "Ringo" :
        ...
        break;
      default:
        ...
        break;
    }


        13.For 循環

    for (int i=0; i<3; i++)
      a(i) = "test";

    Dim I As Integer
      For I = 0 To 2
        a(I) = "test"
      Next

    for (var i : int = 0; i < 3; i++)
      a[i] = "test";


        14.While 循環

    int i = 0;
    while (i<3) {
      Console.WriteLine(i.ToString());
      i += 1;
    }

    Dim I As Integer
    I = 0
    Do While I < 3
      Console.WriteLine(I.ToString())
      I += 1
    Loop

    var i : int = 0;
    while (i < 3) {
      Console.WriteLine(i);
      i += 1;
    }


        15.異常處理

    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 Try

    try {
        // Code that throws exceptions
    } catch(e:OverflowException) {
        // Catch a specific exception
    } catch(e:Exception) {
        // Catch the generic exceptions
    } finally {
        // Execute some cleanup code
    }


        16.字符串連接

    // Using Strings
    String s1;
    String s2 = "hello";
    s2 += " world";
    s1 = s2 + " !!!";

    // Using StringBuilder class for performance
    StringBuilder s3 = new StringBuilder();
    s3.Append("hello");
    s3.Append(" world");
    s3.Append(" !!!");

    ' Using Strings
    Dim s1, s2 As String
    s2 = "hello"
    s2 &= " world"
    s1 = s2 & " !!!"

    ' Using StringBuilder class for performance
    Dim s3 As New StringBuilder()
    s3.Append("hello")
    s3.Append(" world")
    s3.Append(" !!!")

    // Using Strings
    var s1 : String;
    var s2 : String = "hello";
    s2 += " world";
    s1 = s2 + " !!!";

    // Using StringBuilder class for performance
    var s3:StringBuilder = new StringBuilder();
    s3.Append("hello");
    s3.Append(" world");
    s3.Append(" !!!");


        17.事件處理程序委托

    void MyButton_Click(Object sender,
                        EventArgs E) {
    ...
    }

    Sub MyButton_Click(Sender As Object,
                       E As EventArgs)
    ...
    End Sub

    function MyButton_Click(sender : Object,
                            E : EventArgs) {
    ...
    }


        18.聲明事件

    // Create a public event
    public event EventHandler MyEvent;

    // Create a method for firing the event
    protected void OnMyEvent(EventArgs e) {
          MyEvent(this, e);
    }

    ' Create a public event
    Public Event MyEvent(Sender as Object, E as EventArgs)

    ' Create a method for firing the event
    Protected Sub OnMyEvent(E As EventArgs)
        RaiseEvent MyEvent(Me, E)
    End Sub

    JScript 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.


        19.向事件添加事件處理程序或從事件移除事件處理程序

    Control.Change += new EventHandler(this.ChangeEventHandler);
    Control.Change -= new EventHandler(this.ChangeEventHandler);

    AddHandler Control.Change, AddressOf Me.ChangeEventHandler
    RemoveHandler Control.Change, AddressOf Me.ChangeEventHandler

    Control.Change += this.ChangeEventHandler;
    Control.Change -= this.ChangeEventHandler;


        20.強制類型轉換

    MyObject obj = (MyObject)Session["Some Value"];
    IMyObject iObj = obj;

    Dim obj As MyObject
    Dim iObj As IMyObject
    obj = Session("Some Value")
    iObj = CType(obj, IMyObject)

    var obj : MyObject = MyObject(Session("Some Value"));
    var iObj : IMyObject = obj;


        21.轉換

    int i = 3;
    String s = i.ToString();
    double d = Double.Parse(s);

    Dim i As Integer
    Dim s As String
    Dim d As Double

    i = 3
    s = i.ToString()
    d = CDbl(s)

    ' See also CDbl(...), CStr(...), ...

    var i : int = 3;
    var s : String = i.ToString();
    var d : double = Number(s);


        22.帶繼承的類定義

    using System;

    namespace MySpace {

      public class Foo : Bar {

        int x;

        public Foo() { x = 4; }
        public void Add(int x) { this.x += x; }
        override public int GetNum() { return x; }
      }

    }

    // csc /out:librarycs.dll /t:library
    // library.cs


    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

        Overrides Public Function GetNum() As Integer
           Return x
        End Function

      End 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 = 4; }
        function Add(x : int) { this.x += x; }
        override function GetNum() : int { return x; }
      }

    }

    // jsc /out:libraryjs.dll library.js


        23.實現接口

    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 {
             ...
        }
    }


        24.帶 Main 方法的類定義

    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

    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 New ConsoleVB
      End Sub

    End 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


        25.標準模塊

    using System;

    public class Module {

    public static void Main (String[] args) {
      Console.WriteLine("Hello World");
    }

    }
    // csc /out:consolecs.exe /t:exe console.cs

    Imports System

    Public Module ConsoleVB

      Public Sub Main()
        Console.WriteLine("Hello World")
      End Sub

    End Module

    ' vbc /out:consolevb.exe /t:exe console.vb

    print("Hello World");

    // jsc /out:consolejs.exe /exe console.js

    延伸閱讀

    文章來源于領測軟件測試網 http://www.kjueaiud.com/


    關于領測軟件測試網 | 領測軟件測試網合作伙伴 | 廣告服務 | 投稿指南 | 聯系我們 | 網站地圖 | 友情鏈接
    版權所有(C) 2003-2010 TestAge(領測軟件測試網)|領測國際科技(北京)有限公司|軟件測試工程師培訓網 All Rights Reserved
    北京市海淀區中關村南大街9號北京理工科技大廈1402室 京ICP備2023014753號-2
    技術支持和業務聯系:info@testage.com.cn 電話:010-51297073

    軟件測試 | 領測國際ISTQBISTQB官網TMMiTMMi認證國際軟件測試工程師認證領測軟件測試網

    老湿亚洲永久精品ww47香蕉图片_日韩欧美中文字幕北美法律_国产AV永久无码天堂影院_久久婷婷综合色丁香五月

  • <ruby id="5koa6"></ruby>
    <ruby id="5koa6"><option id="5koa6"><thead id="5koa6"></thead></option></ruby>

    <progress id="5koa6"></progress>

  • <strong id="5koa6"></strong>