Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot implicitly convert type 'int?[]' to 'int[]

Tags:

c#

.net

I hahe this segment of code:

    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();
    }

on this row:

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

I get this error:

"Cannot implicitly convert type 'int?[]' to 'int[]'

Any idea how can i fix the error?

Thank you in advance.

like image 240
Michael Avatar asked Feb 20 '26 03:02

Michael


2 Answers

Just change your statement

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

To

int?[] numbers = new int?[] { foundACContours.Count, foundFNContours.Count, 
                             foundBlurContours.Count, foundFilteredContours.Count };
like image 174
Yograj Gupta Avatar answered Feb 21 '26 17:02

Yograj Gupta


int?[] numbers = new int?[] { foundACContours.Count, foundFNContours.Count, foundBlurContours.Count, foundFilteredContours.Count };
like image 22
nils Avatar answered Feb 21 '26 18:02

nils