隐式转换错误

Kri*_*hna 0 c#

请建议我改变..不能隐式地将类型'System.Collections.Generic.List'转换为System.Collections.Generic.IEnumerable'.存在显式转换(您是否错过了演员?)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MyNamespace
{
    class Program
    {
        static void Main(string[] args)
        {
            List<int> eventIDs = new List<int>() { 53,90,344,2223,2225,4497,5512};
            MatchNumbers(eventIDs,2200,2300);

        }
        public static void MatchNumbers(IEnumerable<uint> eventsSet, int lowerBound, int upperBound)
        {
            if (upperBound < lowerBound)
                throw new Exception("Lower bound cant be bigger");
            List<int> itemSet = (List<int>)eventsSet;
            for (int i = lowerBound; i <= upperBound; i++)
            {
                int result = itemSet.BinarySearch(i);
                if (result >= 0)
                    Console.WriteLine("Found{0}", i);
            }
        }

    }
}
Run Code Online (Sandbox Code Playgroud)

Bol*_*ock 6

请建议我改变..

做其中任何一个:

  • 让你的方法接受IEnumerable<int>而不是IEnumerable<uint>.

  • List<uint>而不是List<int>.

int表示32位整数的uint有符号范围,而表示32位整数的无符号范围.由于值范围的差别,你不能换两个泛型类intuint.