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

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

詭異的靜態(tài)構(gòu)造函數(shù)

詭異的靜態(tài)構(gòu)造函數(shù)

胡說叔叔 2018-12-07 06:46:28
public class Rational { protected static Rational one; public static Rational One { get { return one; } } protected static Rational zero; public static Rational Zero { get { return zero; } } { public int N { get; set; } public int M { get; set; } static Rational() { one = new Rational(1, 1); zero = new Rational(0, 1); } public Rational(int n, int m) { N = n; M = m; } public override string ToString() { return string.Format("{0}/{1}", N, M); } } static void Main(string[] args) {? Rational r1 = Rational.One;//r1 is 1/1 Rational r2 = Rational.Zero;//r2 is 0/1 Rational r = new Rational(1, 2);? Rational r3 = Rational.One;//r3 is 1/1? Rational r4 = Rational.Zero;//r4 is 0/1 }?但是: public class Ra { protected static Rational one; public static Rational One { get { return one; } } protected static Rational zero; public static Rational Zero { get { return zero; } } } public class Rational:Ra { public int N { get; set; } public int M { get; set; } static Rational() { one = new Rational(1, 1); zero = new Rational(0, 1); } public Rational(int n, int m) { N = n; M = m; } public override string ToString() { return string.Format("{0}/{1}", N, M); } } ? static void Main(string[] args) {? Rational r1 = Rational.One;//r1 is null? Rational r2 = Rational.Zero;//r2 is null Rational r = new Rational(1, 2);? Rational r3 = Rational.One;//r3 is 1/1? Rational r4 = Rational.Zero;//r4 is 0/1 }字段在類中,靜態(tài)構(gòu)造函數(shù)會(huì)在第一次調(diào)用屬性之前調(diào)用初始化靜態(tài)字段,但是字段繼承于基類,靜態(tài)構(gòu)造不會(huì)在調(diào)用屬性之前初始為,而是在實(shí)例化類之后初始化,什么原因,什么解決辦法?
查看完整描述

1 回答

  • 1 回答
  • 0 關(guān)注
  • 228 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號(hào)

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