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

标签 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[]’

知道如何修复错误吗?

提前谢谢你。

最佳答案

只是改变你的声明

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

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

关于c# - 无法将类型 'int?[]' 隐式转换为 'int[],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13173332/

相关文章:

c# - 如何限制对方法的访问,仅允许特定程序集访问它们?

c# Directory.CreateDirectory( path ),我应该先检查路径是否存在吗?

c# - 将控件拖放到自定义用户控件上会隐藏

c# - 连接到 WSDL 时遇到问题

c# - C# 中如何检查日期是否已过?

.net - EntLib 缓存应用程序 block 的替代方案?

c# - 从 .NET 迁移到 Java

c# - 有没有一种简单的方法来获取 .NET 为参数化查询生成的 "sp_executesql"查询?

.net - 命名为 RowDefinition 的网格无法作为 WPF4 中的 ItemsPanel 填充

.net - System.Net.Http.HttpClient 是否受到 HttpWebRequest.AllowWriteStreamBuffering 的影响?