2010年12月15日 星期三

基本語法

---------------------------------------------------------------------------
       Response.Write("Hello 099007");


       // a= Hello 099007

---------------------------------------------------------------------------
        string u_word;
        u_word = "Hello 099007";
        Response.Write(u_word);


       // a= Hello 099007
--------------------------------讀檔-------------------------------------------

       Response.WriteFile("123.txt");
    //    a= 123.txt的內容
--------------------------------超連結-------------------------------------------

 Response.Redirect("http://www.hwc.edu.tw/");

--------------------------------if-------------------------------------------


        if (true)
        {
            Response.Redirect("http://google.com/");
        }
        else
        {
            Response.Redirect("http://www.hwc.edu.tw/");
        }

//a= http://google.com/

       if (false)
        {
            Response.Redirect("http://google.com/");
        }
        else
        {
            Response.Redirect("http://www.hwc.edu.tw/");
        }

//a= http://www.hwc.edu.tw/


           if (Convert.ToInt64(TextBox1.Text)==1)
        {
            Response.Redirect("http://google.com/");
        }
        else
        {
            Response.Redirect("http://www.hwc.edu.tw/");
        }

--------------------------------if-------------------------------------------
if (Convert.ToInt64(TextBox1.Text)==1)
        {
            Response.Redirect("http://google.com/");
        }
        if (Convert.ToInt64(TextBox1.Text) == 2)
        {
            Response.Redirect("http://www.hwc.edu.tw/");
        }
        if (Convert.ToInt64(TextBox1.Text) == 3)
        {
            Response.Redirect("http://tw.yahoo.com/");
        }
        else
        {
            Response.Redirect("http://pchome.com.tw/");
        }


--------------------------------switch -------------------------------------------
          int u_int = Convert.ToInt16(TextBox1.Text);
        switch (u_int)
        {
            case 1:
                Response.Redirect("http://www.hwc.edu.tw/");
                break;
            case 2:
                Response.Redirect("http://google.com.tw/");
                break;
            default:
                Response.Redirect("http://tw.yahoo.com/");
                break;
        }

--------------------------------QueryString-------------------------------------------
 int a = Convert.ToInt16(Request.QueryString["u_number"]);
        if (a > 10)
        {
            Response.Write("大於十");
        }
        else
        {
            Response.Write("小於十");
        }


ex:  http://localhost:2091/WebSite1/Default.aspx?u_number=9

--------------------------------巢狀if-------------------------------------------
        int a = Convert.ToInt16(Request.QueryString["u_number"]);
        if (a > 10)
        {
            Response.Write("大於十");
        }
        else
        {
            if (a == 10)
            {
                Response.Write("等於十");

               
            }
            else
            {
                Response.Write("小於十");
            }
        }


--------------------------------for-------------------------------------------
        int my_sum=0;
        for (int i = 0; i <= 2; i++)
        {
            my_sum = my_sum + i;           
        }
        Response.Write(my_sum);

--------------------------------for if 混合運用-------------------------------------------
  for (int i = 2; i <= 9; i++)
        {
            for (int j = 1; j <= 9; j++)
            {
                Response.Write(i + "x" + j + "=" + i * j + "&#9;");
                if (j == 9)
                {
                    Response.Write("<br>");
                }
            }
        }

--------------------------------while-------------------------------------------
        int i=0;
        while (i <= 100)
        {
            Response.Write(i+"<br>");
            i = i + 1;
        }

沒有留言:

張貼留言