freepeople性欧美熟妇, 色戒完整版无删减158分钟hd, 无码精品国产vα在线观看DVD, 丰满少妇伦精品无码专区在线观看,艾栗栗与纹身男宾馆3p50分钟,国产AV片在线观看,黑人与美女高潮,18岁女RAPPERDISSSUBS,国产手机在机看影片

正文內(nèi)容

面向?qū)ο蠛皖惖脑O(shè)計(jì)-資料下載頁

2025-08-16 00:05本頁面
  

【正文】 值了。 ? 有沒有一種途徑,它可以讓使用者像使用公共的字段一樣方便,又能讓設(shè)計(jì)者能夠進(jìn)行安全地檢查? 使用屬性 ? 我們可以使用 屬性 來解決這個(gè)問題。 ? 屬性,從外部 (類的使用者 )來看,類似于類的字段。 從內(nèi)部 (類的作者 )來看,類似于類的方法 。 get訪問器 set訪問器 MyTime preTime = new MyTime(19, 34, 56)。 MyTime nowTime = new MyTime(21, 45, 26)。 //這句錯(cuò)誤,因?yàn)?hour為私有域,不能在 MyTime類外被訪問 int elapsedHour = 。//error! int elapsedHour = 。//Correct! = 106。 += 20。 先調(diào)用 Second屬性的一次 Get 操作,再調(diào)用一次 Set操作 調(diào)用 set操作,但由于 if條件不滿足, minute不變 屬性成員 ? 變量成員本質(zhì)上就是變量,而屬性成員更大程度上是函數(shù)成員的一種,只是操作時(shí)形式比較類似變量訪問 ? 屬性成員在訪問修飾符的基礎(chǔ)上通過 get/set函數(shù)提供對屬性的更為靈活、安全的訪問控制,可為(私有) 的變量成員多一層邏輯保護(hù),而變量成員只能通過訪問修飾符提供基本的數(shù)據(jù)隱藏功能 ? 屬性成員可通過只公開 get/set,實(shí)現(xiàn)成員的只讀 /只寫 ,而變量要么全部可見要么全不可見 自動屬性 class A { int length。 public int Length { get { return length。 } set { length = value。 } } } class A { public int Length { get。 set。 } } 等價(jià) 他的操作,必須單獨(dú)創(chuàng)建訪問器 索引器 ?索引器是 C 的簡單組件 ? 索引器通常在包含元素集合的類中定義 ? 為數(shù)組創(chuàng)建索引器后,可以通過從類對象指定索引來直接訪問數(shù)組元素 ? 可以用索引數(shù)組的方式索引對象 ? 可以像訪問數(shù)組一樣訪問類的成員,而不用將內(nèi)部的細(xì)節(jié)暴露給用戶 class IndexerExample { public string[] stringList=new string[10]。 public string this[int index] { get{ return stringList[index]。 } set{ stringList[index] = ()。 } } } class Test { static void Main() { IndexerExample indexTest = new IndexerExample()。 [1]=Sam。 indexTest[2]=Tom。 (“indexTest[1]是 {0}\nindexTest[2]是 {1}, indexTest[1], indexTest[2])。 } } 定義索引器的規(guī)則 ? 必須指定至少一個(gè)索引器參數(shù) ? 應(yīng)當(dāng)為索引器參數(shù)賦值 ? 示例:使用索引給學(xué)生打分 索引器與數(shù)組的比較 41 ? 索引器不指向內(nèi)存位置 ? 索引器可以有非整數(shù)的下標(biāo)(索引) ? 可以重載索引器 索引器與數(shù)組的比較 42 索引器與數(shù)組的比較 43 using 。 class StrIndex { public Hashtable studentList = new Hashtable()。 public int this[string name] { get { return (int) studentList[name]。 } set { studentList[name] = value。 } } } class Test { static void Main() { StrIndex objIndex = new StrIndex()。 objIndex[Sam] = 232676。 objIndex[Tom] = 455464。 (Sam 的電話號碼是 {0}, Tom 的電話號碼是 {1}, objIndex[Sam],objIndex[Tom])。 } } 索引器可以有非整數(shù)下標(biāo) 而數(shù)組不能有 學(xué)生通訊錄示例 索引器與數(shù)組的比較 44 using 。 class IndexerExample { public string[] stringList=new string[10]。 public string this[int index] { get { return stringList[index]。 } set { stringList[index] = ()。 } } public Hashtable studentList=new Hashtable()。 public int this[string number] { get{return (int)studentList[number]。} set { studentList[number] = value。 } } } 一個(gè)類可以有多個(gè)索引器 但必須通過指定不同的 索引類型重載索引器 class Test { static void Main() { IndexerExample indexTest = new IndexerExample()。 [1]=Sam。 indexTest[2]=Tom。 indexTest[Sam] = 232。 indexTest[Tom] = 455。 } } 訪問 stringList 訪問 studentList 在索引器中使用多個(gè)參數(shù) ? 可以指定多個(gè)索引器參數(shù) 編碼風(fēng)格 ? 方法應(yīng)簡短,開始給出注釋,說明輸入、輸出參數(shù)及其完成的主要功能 ? 最好含有 return語句,但數(shù)量不要太多 ? 采用統(tǒng)一的縮進(jìn),良好的可讀性 LibM完整版
點(diǎn)擊復(fù)制文檔內(nèi)容
物理相關(guān)推薦
文庫吧 www.dybbs8.com
備案圖鄂ICP備17016276號-1