av激情亚洲男人的天堂国语,日韩欧美精品一中文字幕,无码av一区二区三区无码,国产又色又爽又刺激的a片,国产又色又爽又刺激的a片

C#3.0新特性的介紹(自動(dòng)屬性)

萬丈高樓平地起,基礎(chǔ)是重中之重。

創(chuàng)新互聯(lián)公司是專業(yè)的羅源網(wǎng)站建設(shè)公司,羅源接單;提供網(wǎng)站制作、網(wǎng)站建設(shè),網(wǎng)頁設(shè)計(jì),網(wǎng)站設(shè)計(jì),建網(wǎng)站,PHP網(wǎng)站建設(shè)等專業(yè)做網(wǎng)站服務(wù);采用PHP框架,可快速的進(jìn)行羅源網(wǎng)站開發(fā)網(wǎng)頁制作和功能擴(kuò)展;專業(yè)做搜索引擎喜愛的網(wǎng)站,專業(yè)的做網(wǎng)站團(tuán)隊(duì),希望更多企業(yè)前來合作!

所有我一定要搞點(diǎn)基礎(chǔ)的東西,雖然已經(jīng)是搞了幾年程序了,有些基礎(chǔ)知識(shí)也懂,但是沒有系統(tǒng)的掌握。

而且發(fā)現(xiàn)現(xiàn)在弄的B/S系統(tǒng)里很多技術(shù)真的很落后了,也許我現(xiàn)在學(xué)的新技術(shù)有些用不上,并不代表不要學(xué),

所有現(xiàn)在開始更加要全部重新學(xué)習(xí)或者復(fù)習(xí)一些基礎(chǔ)東西。

C# 3.0新特性之自動(dòng)屬性(Auto-Implemented Properties)

類的定義

 
 
 
  1. public class Point  
  2. {  
  3.     private int x;  
  4.     private int y;  
  5.  
  6.     public int X { get { return x; } set { x = value; } }  
  7.     public int Y { get { return y; } set { y = value; } }  

與下面這樣定義等價(jià),這就是c#3.0新特性

 
 
 
  1. public class Point  
  2. {  
  3.     public int X {get; set;}  
  4.     public int Y {get; set;}  
  5. }  
  6.  
  7. 一個(gè)例子源碼  
  8. using System;  
  9. using System.Collections.Generic;  
  10. using System.Linq;  
  11. using System.Text;  
  12.  
  13. namespace NewLanguageFeatures1  
  14. {  
  15.     public class Customer  
  16.     {  
  17.         public int CustomerId { get; private set; }  
  18.         public string Name { get; set; }  
  19.         public string City { get; set; }  
  20.  
  21.         public override string ToString()  
  22.         {  
  23.             return Name + “\t” + City + “\t” + CustomerId;  
  24.         }  
  25.  
  26.     }  
  27.     class Program  
  28.     {  
  29.         static void Main(string[] args)  
  30.         {  
  31.             Customer c = new Customer();  
  32.             c.Name = “Alex Roland”;  
  33.             c.City = “Berlin”;  
  34.             c.CustomerId = 1;  
  35.  
  36.             Console.WriteLine(c);  
  37.  
  38.         }  
  39.  
  40.          
  41.     }  

錯(cuò)誤 1 由于 set 訪問器不可訪問,因此不能在此上下文中使用屬性或索引器“NewLanguageFeatures1.Customer.CustomerId” D:\net\NewLanguageFeatures\NewLanguageFeatures1\Program.cs 41 13 NewLanguageFeatures1

Program output showing the result of calling ToString on the Customer class after adding a new CustomerId property

正確的例子源碼:

 
 
 
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Text;  
  5.  
  6. namespace NewLanguageFeatures  
  7. {  
  8.     public class Customer  
  9.     {  
  10.         public int CustomerId { get; private set; }  
  11.  
  12.         public string Name { get; set; }  
  13.         public string City { get; set; }  
  14.  
  15.         public Customer(int Id)  
  16.         {  
  17.             CustomerId = Id;  
  18.         }  
  19.  
  20.         public override string ToString()  
  21.         {  
  22.             return Name + “\t” + City + “\t” + CustomerId;  
  23.         }  
  24.     }  
  25.  
  26.     class Program  
  27.     {  
  28.         static void Main(string[] args)  
  29.         {  
  30.             Customer c = new Customer(1);  
  31.             c.Name = “Alex Roland”;  
  32.             c.City = “Berlin”;  
  33.  
  34.             Console.WriteLine(c);  
  35.         }  
  36.     }  

關(guān)于C#3.0新特性的自動(dòng)屬性功能就討論到這里,希望對(duì)大家有用。


網(wǎng)頁名稱:C#3.0新特性的介紹(自動(dòng)屬性)
當(dāng)前URL:http://uogjgqi.cn/article/cdegjoc.html
掃二維碼與項(xiàng)目經(jīng)理溝通

我們?cè)谖⑿派?4小時(shí)期待你的聲音

解答本文疑問/技術(shù)咨詢/運(yùn)營(yíng)咨詢/技術(shù)建議/互聯(lián)網(wǎng)交流