亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

將派生類的List <>轉換為基類的List <>

將派生類的List <>轉換為基類的List <>

C#
catspeake 2019-12-05 13:17:17
我有兩個類:一個基類(Animal)和一個從它派生的類(Cat)?;惏粋€虛擬方法Play,它以List作為輸入參數。using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace ConsoleApplication9{    class Animal    {        public virtual void Play(List<Animal> animal) { }    }    class Cat : Animal    {        public override void Play(List<Animal> animal)        {        }    }    class Program    {        static void Main(string[] args)        {            Cat cat = new Cat();            cat.Play(new List<Cat>());        }    }}當我編譯上面的程序時,出現以下錯誤    錯誤2參數1:無法從“ System.Collections.Generic.List”轉換為“ System.Collections.Generic.List”反正有做到這一點嗎?C# 泛型
查看完整描述

3 回答

  • 3 回答
  • 0 關注
  • 862 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號