成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

ASP.NET基礎語法概覽

開發 后端
本文總結了一些ASP.NET基礎語法,以供初學者參考。通過學習以下的代碼可以幫助你迅速上手。

本文提供的的代碼段幫助你理解ASP.NET的基礎語法。

變量聲明

  1. int x;   
  2. String s;   
  3. String s1, s2;   
  4. Object o;   
  5. Object obj = new Object();   
  6. public String name;   
  7.  

語句

  1. Response.Write("foo");  

注釋

  1. // 這是單行注釋   
  2. /*   
  3. 這是   
  4. 多   
  5. 行   
  6. 注釋*/   
  7.  

訪問索引屬性

  1. String s = Request.QueryString["Name"];   
  2. String value = Request.Cookies["key"];  

聲明索引屬性

  1. // Default Indexed Property   
  2. public String this[String name] {   
  3. get {   
  4. return (String) lookuptable[name];   
  5. }   
  6. }   
  7.  

聲明簡單屬性

  1. public String name {   
  2. get {   
  3. ...   
  4. return ...;   
  5. }   
  6. set {   
  7. ... = value;   
  8. }   
  9. }   
  10.  

聲明和使用枚舉

  1. // Declare the Enumeration   
  2. public enum MessageSize {   
  3. Small = 0,   
  4. Medium = 1,   
  5. Large = 2   
  6. }   
  7. // Create a Field or Property   
  8. public MessageSize msgsize;   
  9. // Assign to the property using the Enumeration values   
  10. msgsize = Small;   

遍歷集合

  1. foreach ( String s in coll ) {   
  2. ...   
  3. }   
  4.  

聲明和使用方法

  1. // Declare a void return function   
  2. void voidfunction() {   
  3. ...   
  4. }   
  5. // Declare a function that returns a value   
  6. String stringfunction() {   
  7. ...   
  8. return (String) val;   
  9. }   
  10. // Declare a function that takes and returns values   
  11. String parmfunction(String a, String b) {   
  12. ...   
  13. return (String) (a + b);   
  14. }   
  15. // Use the Functions   
  16. voidfunction();   
  17. String s1 = stringfunction();   
  18. String s2 = parmfunction("Hello""World!");   

定制屬性

  1. // Stand-alone attribute   
  2. [STAThread]   
  3. // Attribute with parameters   
  4. [DllImport("ADVAPI32.DLL")]   
  5. // Attribute with named parameters   
  6. [DllImport("KERNEL32.DLL", CharSet=CharSet.Auto)]   
  7.  

數組

  1. String[] a = new String[3];  
  2. a[0] = "1";  
  3. a[1] = "2";  
  4. a[2] = "3";  
  5. String[][] a = new String[3][3];  
  6. a[0][0] = "1";  
  7. a[1][0] = "2";  
  8. a[2][0] = "3";  

初始化

  1. String s = "Hello World";  
  2. int i = 1;  
  3. double[] a = { 3.00, 4.00, 5.00 };  

ASP.NET基礎語法:語句

If 語句

  1. if (Request.QueryString != null) {  
  2. ...  
  3. }  

Case 語句

  1. switch (FirstName) {  
  2. case "John" :  
  3. ...  
  4. break;  
  5. case "Paul" :  
  6. ...  
  7. break;  
  8. case "Ringo" :  
  9. ...  
  10. break;  
  11. default:  
  12. ...  
  13. break;  
  14. }  

For 循環

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

While 循環

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

異常處理

  1. try {  
  2. // Code that throws exceptions  
  3. catch(OverflowException e) {  
  4. // Catch a specific exception  
  5. catch(Exception e) {  
  6. // Catch the generic exceptions  
  7. finally {  
  8. // Execute some cleanup code  
  9. }  

字符串連接

  1. // Using Strings  
  2. String s1;  
  3. String s2 = "hello";  
  4. s2 += " world";  
  5. s1 = s2 + " !!!";  
  6. // Using StringBuilder class for performance  
  7. StringBuilder s3 = new StringBuilder();  
  8. s3.Append("hello");  
  9. s3.Append(" world");  
  10. s3.Append(" !!!");  

事件處理委派

  1. void MyButton_Click(Object sender,  
  2. EventArgs E) {  
  3. ...  
  4. }  

聲明事件

  1. // Create a public event  
  2. public event EventHandler MyEvent;  
  3. // Create a method for firing the event  
  4. protected void OnMyEvent(EventArgs e) {  
  5. MyEvent(this, e);  
  6. }  

向事件增加或移除事件處理

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

構造

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

轉換

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

帶有繼承的類定義

  1. using System;  
  2. namespace MySpace {  
  3. public class Foo : Bar {  
  4. int x;  
  5. public Foo() { x = 4; }  
  6. public void Add(int x) { this.x += x; }  
  7. override public int GetNum() { return x; }  
  8. }  
  9. }  
  10. // csc /out:librarycs.dll /t:library  
  11. // library.cs  

實現接口

  1. public class MyClass : IEnumerable {  
  2. ...  
  3. IEnumerator IEnumerable.GetEnumerator() {  
  4. ...  
  5. }  
  6. }  

帶有Main方法的類定義

  1. using System;  
  2. public class ConsoleCS {  
  3. public ConsoleCS() {  
  4. Console.WriteLine("Object Created");  
  5. }  
  6. public static void Main (String[] args) {  
  7. Console.WriteLine("Hello World");  
  8. ConsoleCS ccs = new ConsoleCS();  
  9. }  
  10. }  
  11. // csc /out:consolecs.exe /t:exe console.cs  

標準模板

  1. using System;  
  2. public class Module {  
  3. public static void Main (String[] args) {  
  4. Console.WriteLine("Hello World");  
  5. }  
  6. }  
  7. // csc /out:consolecs.exe /t:exe console.cs  

以上就介紹了ASP.NET基礎語法。

【編輯推薦】

  1. ASP.NET安裝部署之創建安裝程序類
  2. ASP.NET安裝部署代碼實現
  3. ASP.NET安裝包制作圖解
  4. ASP.NET安裝包制作之卸載功能
  5. ASP.NET安裝環境淺析
責任編輯:yangsai 來源: 網易博客
相關推薦

2009-08-24 16:46:58

什么是ASP.NET

2009-07-27 13:34:15

ASP.NET編程

2009-08-03 15:53:11

ASP.NET移動開發

2009-08-17 16:59:36

ASP.NET緩存機制

2009-07-22 17:45:35

ASP.NET教程

2009-08-03 14:22:33

什么是ASP.NET

2009-07-28 17:17:19

ASP.NET概述

2009-07-27 12:22:03

ASP.NET和ASPASP.NET入門教程

2009-08-10 13:32:15

ASP.NET TimASP.NET組件設計

2009-07-29 17:11:25

ASP.NET ISA

2009-07-29 16:08:07

ASP和ASP.NET

2009-08-03 13:38:18

ASP.NET編程模型

2009-07-23 13:30:12

ASP.NET數組

2009-07-27 16:11:01

ASP.NET網頁模板

2009-08-07 14:42:02

ASP.NET控件開發

2009-07-28 09:02:32

asp.net aja

2009-08-03 17:35:07

ASP.NET WebASP.NET編程工具

2009-12-02 09:07:45

ASP.NET 4.0

2009-07-20 15:30:11

ASP.NET應用

2009-07-22 16:11:43

ASP.NET AJA
點贊
收藏

51CTO技術棧公眾號

主站蜘蛛池模板: 欧美一级片在线看 | 日本在线视频一区二区 | 国内精品久久久久 | 久久一区二区三区四区五区 | 欧美成人免费在线视频 | 久久久久国产精品 | 91精品国产综合久久婷婷香蕉 | 日本五月婷婷 | 亚洲一区二区三区在线播放 | 亚洲欧美网 | 成人欧美一区二区三区黑人孕妇 | 欧美日韩不卡在线 | 在线欧美小视频 | 成人激情免费视频 | 四色成人av永久网址 | 亚洲天堂网站 | 羞羞色在线观看 | 岛国午夜 | 岛国av免费看 | 美女一级毛片 | 91免费福利在线 | 亚洲欧美一区二区三区在线 | 91精品久久久久久久久久 | 毛片毛片毛片毛片毛片 | 大陆一级毛片免费视频观看 | 国产美女在线观看 | 国产精品乱码一区二区三区 | 精品一区二区三区四区 | 国产玖玖 | 综合一区 | 九九福利| 国产亚洲欧美在线视频 | 国产成人精品一区二区三 | 欧美一级片在线看 | 91在线区| 精品综合 | 国产999精品久久久影片官网 | 91精品国产色综合久久不卡98 | 日韩在线 | 欧美日韩国产一区二区三区 | 日韩欧美精品在线 |