這篇文章主要介紹“ASP.NET基礎(chǔ)語法有哪些”,在日常操作中,相信很多人在ASP.NET基礎(chǔ)語法有哪些問題上存在疑惑,小編查閱了各式資料,整理出簡單好用的操作方法,希望對(duì)大家解答”ASP.NET基礎(chǔ)語法有哪些”的疑惑有所幫助!接下來,請(qǐng)跟著小編一起來學(xué)習(xí)吧!
望謨網(wǎng)站制作公司哪家好,找創(chuàng)新互聯(lián)!從網(wǎng)頁設(shè)計(jì)、網(wǎng)站建設(shè)、微信開發(fā)、APP開發(fā)、成都響應(yīng)式網(wǎng)站建設(shè)公司等網(wǎng)站項(xiàng)目制作,到程序開發(fā),運(yùn)營維護(hù)。創(chuàng)新互聯(lián)于2013年成立到現(xiàn)在10年的時(shí)間,我們擁有了豐富的建站經(jīng)驗(yàn)和運(yùn)維經(jīng)驗(yàn),來保證我們的工作的順利進(jìn)行。專注于網(wǎng)站建設(shè)就選創(chuàng)新互聯(lián)。
變量聲明
int x; String s; String s1, s2; Object o; Object obj = new Object(); public String name;
語句
Response.Write("foo");
注釋
// 這是單行注釋 /* 這是 多 行 注釋*/
訪問索引屬性
String s = Request.QueryString["Name"]; String value = Request.Cookies["key"];
聲明索引屬性
// Default Indexed Property public String this[String name] { get { return (String) lookuptable[name]; } }
聲明簡單屬性
public String name { get { ... return ...; } set { ... = value; } }
聲明和使用枚舉
// Declare the Enumeration public enum MessageSize { Small = 0, Medium = 1, Large = 2 } // Create a Field or Property public MessageSize msgsize; // Assign to the property using the Enumeration values msgsize = Small;
遍歷集合
foreach ( String s in coll ) { ... }
聲明和使用方法
// Declare a void return function void voidfunction() { ... } // Declare a function that returns a value String stringfunction() { ... return (String) val; } // Declare a function that takes and returns values String parmfunction(String a, String b) { ... return (String) (a + b); } // Use the Functions voidfunction(); String s1 = stringfunction(); String s2 = parmfunction("Hello", "World!");
定制屬性
// Stand-alone attribute [STAThread] // Attribute with parameters [DllImport("ADVAPI32.DLL")] // Attribute with named parameters [DllImport("KERNEL32.DLL", CharSet=CharSet.Auto)]
數(shù)組
String[] a = new String[3]; a[0] = "1"; a[1] = "2"; a[2] = "3"; String[][] a = new String[3][3]; a[0][0] = "1"; a[1][0] = "2"; a[2][0] = "3";
初始化
String s = "Hello World"; int i = 1; double[] a = { 3.00, 4.00, 5.00 };
ASP.NET基礎(chǔ)語法:語句
If 語句
if (Request.QueryString != null) { ... }
Case 語句
switch (FirstName) { case "John" : ... break; case "Paul" : ... break; case "Ringo" : ... break; default: ... break; }
For 循環(huán)
for (int i=0; i<3; i++) a(i) = "test";
While 循環(huán)
int i = 0; while (i<3) { Console.WriteLine(i.ToString()); i += 1; }
異常處理
try { // Code that throws exceptions } catch(OverflowException e) { // Catch a specific exception } catch(Exception e) { // Catch the generic exceptions } finally { // Execute some cleanup code }
字符串連接
// 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(" !!!");
事件處理委派
void MyButton_Click(Object sender, EventArgs E) { ... }
聲明事件
// Create a public event public event EventHandler MyEvent; // Create a method for firing the event protected void OnMyEvent(EventArgs e) { MyEvent(this, e); }
向事件增加或移除事件處理
Control.Change += new EventHandler(this.ChangeEventHandler); Control.Change -= new EventHandler(this.ChangeEventHandler);
構(gòu)造
MyObject obj = (MyObject)Session["Some Value"]; IMyObject iObj = obj;
轉(zhuǎn)換
int i = 3; String s = i.ToString(); double d = Double.Parse(s);
帶有繼承的類定義
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
實(shí)現(xiàn)接口
public class MyClass : IEnumerable { ... IEnumerator IEnumerable.GetEnumerator() { ... } }
帶有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
標(biāo)準(zhǔn)模板
using System; public class Module { public static void Main (String[] args) { Console.WriteLine("Hello World"); } } // csc /out:consolecs.exe /t:exe console.cs
到此,關(guān)于“ASP.NET基礎(chǔ)語法有哪些”的學(xué)習(xí)就結(jié)束了,希望能夠解決大家的疑惑。理論與實(shí)踐的搭配能更好的幫助大家學(xué)習(xí),快去試試吧!若想繼續(xù)學(xué)習(xí)更多相關(guān)知識(shí),請(qǐng)繼續(xù)關(guān)注創(chuàng)新互聯(lián)網(wǎng)站,小編會(huì)繼續(xù)努力為大家?guī)砀鄬?shí)用的文章!
新聞名稱:ASP.NET基礎(chǔ)語法有哪些
URL鏈接:http://jinyejixie.com/article0/jogiio.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供小程序開發(fā)、面包屑導(dǎo)航、網(wǎng)站制作、網(wǎng)頁設(shè)計(jì)公司、響應(yīng)式網(wǎng)站、定制網(wǎng)站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)