日本综合一区二区|亚洲中文天堂综合|日韩欧美自拍一区|男女精品天堂一区|欧美自拍第6页亚洲成人精品一区|亚洲黄色天堂一区二区成人|超碰91偷拍第一页|日韩av夜夜嗨中文字幕|久久蜜综合视频官网|精美人妻一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問(wèn)題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷解決方案
C#3.0新特性的介紹(自動(dòng)屬性)

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

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

所有我一定要搞點(diǎn)基礎(chǔ)的東西,雖然已經(jīng)是搞了幾年程序了,有些基礎(chǔ)知識(shí)也懂,但是沒(méi)有系統(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 訪問(wèn)器不可訪問(wèn),因此不能在此上下文中使用屬性或索引器“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)前網(wǎng)址:http://www.dlmjj.cn/article/cdegjoc.html