第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

如何在 C# 中創(chuàng)建可通過 Intellisense 訪問的變量

如何在 C# 中創(chuàng)建可通過 Intellisense 訪問的變量

C#
達(dá)令說 2021-11-14 15:51:43
我開始使用 C# 并且仍在學(xué)習(xí)基礎(chǔ)知識(shí)。我有幾個(gè)不同的類:public class CompanyA{}public class CompanyB{}...我需要為每家公司定義成人、兒童和嬰兒年齡,然后我可以使用 Intellisense 訪問這些“int”值,并且我可以在其中為每個(gè)公司初始化“maxAge”和“minAge”。我相信它會(huì)是這樣的:CompanyA.Adult.minAgeCompanyB.Infant.maxAge你能否提供一個(gè)我如何實(shí)現(xiàn)這一目標(biāo)的例子?我需要?jiǎng)?chuàng)建其他類似的結(jié)構(gòu),所以有一個(gè)工作示例會(huì)對(duì)我有很大幫助。
查看完整描述

2 回答

?
白豬掌柜的

TA貢獻(xiàn)1893條經(jīng)驗(yàn) 獲得超10個(gè)贊

首先定義您的類,然后您可以從智能感知訪問它們。


public class CompanyA

{

    public Adult Adult { get; set; }

    public Infant Infant { get; set; }

}


public class CompanyB

{

    public Adult Adult { get; set; }

    public Infant Infant { get; set; }

}


public class Adult 

{

    public int MaxAge { get; set; }

    public int MinAge { get; set; }

}


public class Infant

{

    public int MaxAge { get; set; }

    public int MinAge { get; set; }

}

現(xiàn)在您可以像這樣訪問它們:


CompanyA.Adult.MinAge

CompanyB.Infant.MaxAge

在你的職業(yè)生涯中有很多好運(yùn)。


編輯:


正如 Jay 在評(píng)論中建議的那樣,您應(yīng)該了解訪問修飾符的工作原理。這是一個(gè)指南。


查看完整回答
反對(duì) 回復(fù) 2021-11-14
?
慕容3067478

TA貢獻(xiàn)1773條經(jīng)驗(yàn) 獲得超3個(gè)贊

上面的例子為我指明了正確的方向。最后,我設(shè)法使用以下代碼訪問它們:


public class Ages 

{

    public int MaxAge { get; set; }

    public int MinAge { get; set; }

}


public class CompanyA

{

    public Ages Adult = new Ages { MinAge = 14, MaxAge = 55 };

    public Ages Infant = new Ages { MinAge = 0, MaxAge = 4 };

}


public class CompanyB

{

    public Ages Adult = new Ages { MinAge = 18, MaxAge = 60 };

    public Ages Infant = new Ages { MinAge = 0, MaxAge = 2 };

}


查看完整回答
反對(duì) 回復(fù) 2021-11-14
  • 2 回答
  • 0 關(guān)注
  • 222 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)