小编SPF*_*ake的帖子

C#中的转换问题

我有一个程序

using System;
using System.Collections.Generic;

namespace Generic
{
    public class Program
    {
        public static void Main()
        {
            List<string> dd= Program.get();
        }

        public static IList<string> get()
        {
            List<string> str = new List<string>();
            return str;  
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

在执行上面我得到:

无法隐式转换 'System.Collections.Generic.IList<string>'
'System.Collections.Generic.List<string>'.存在显式转换(您是否错过了演员?).

既然,List派生IList,这不应该失败.那么为什么C#会抛出这个错误呢?

c# oop

0
推荐指数
1
解决办法
98
查看次数

标签 统计

c# ×1

oop ×1