无法将类型'int?[]'隐式转换为'int []

时间:2012-11-01 08:21:09

标签: c# .net

我喜欢这段代码:

    private FoundContours SelectFromFoundSamples(FoundContours foundACContours, FoundContours foundFNContours, FoundContours foundBlurContours, FoundContours foundFilteredContours)
    {

        int? num = null;

        int? a = null, b = null, c = null, d = 10;


        int?[] numbers = new[] { foundACContours.Count, foundFNContours.Count, foundBlurContours.Count, foundFilteredContours.Count };

        int? max = numbers.Max();
    }

在这一行:

int?[] numbers = new[] { foundACContours.Count, foundFNContours.Count, foundBlurContours.Count, foundFilteredContours.Count };

我收到此错误:

“不能将类型'int?[]'隐式转换为'int []'

知道如何修复错误?

提前谢谢。

2 个答案:

答案 0 :(得分:7)

只需更改您的陈述

int?[] numbers = new[] { foundACContours.Count, foundFNContours.Count, 
                         foundBlurContours.Count, foundFilteredContours.Count };

int?[] numbers = new int?[] { foundACContours.Count, foundFNContours.Count, 
                             foundBlurContours.Count, foundFilteredContours.Count };

答案 1 :(得分:3)

int?[] numbers = new int?[] { foundACContours.Count, foundFNContours.Count, foundBlurContours.Count, foundFilteredContours.Count };