最近中文字幕高清中文字幕无,亚洲欧美高清一区二区三区,一本色道无码道dvd在线观看 ,一个人看的www免费高清中文字幕

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

dynamic轉(zhuǎn)換類型

dynamic轉(zhuǎn)換類型

手掌心 2018-07-27 13:11:38
EntityBase是基類IBLLBase<T> where T:EntityBase,new() 是基類接口Test是實(shí)體類TestBLL是接口實(shí)現(xiàn)類下面是某個(gè)類里面的的索引public IBLLBase<dynamic> this[string name]{  get  {    switch (name.ToLower())    {      case"test":      return (IBLLBase<Test>)new TestBLL();    }    return null;  }}錯(cuò)誤:Test無(wú)法轉(zhuǎn)換成dynamic類型。誰(shuí)知道怎么做才能把Test轉(zhuǎn)換成dynamic?
查看完整描述

2 回答

?
慕勒3428872

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

因?yàn)槟愕腎BLLBase<T>不支持協(xié)變,而且你的T限制了只能是EntityBase,因此答案就是“不能”。話說(shuō)我很好奇你這么做意義很在,感覺除了測(cè)試,沒什么用。

查看完整回答
反對(duì) 回復(fù) 2018-07-30
?
慕碼人2483693

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

class Base { 
    
    }    //協(xié)變定義,流暢轉(zhuǎn)換成子類型
    interface IBase<out T> where T : Base, new() {        void SomeMethod();        
    }    class Derived:Base { 
    
    }    class Implementation : IBase<Derived> {        public void SomeMethod()
        {
        }
    }    class DoSomething {        //dynamic 不能作為類型參數(shù)
        public IBase<Base> this[string name]
        {            get {                if (name == "")
                {                    return new Implementation();
                }                else
                    return null;
            }
        }
    }


查看完整回答
反對(duì) 回復(fù) 2018-07-30
  • 2 回答
  • 0 關(guān)注
  • 1371 瀏覽

添加回答

舉報(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)