Michael
Michael

Reputation: 13636

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

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.

Upvotes: 2

Views: 2383

Answers (2)

nils
nils

Reputation: 678

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

Upvotes: 3

Yograj Gupta
Yograj Gupta

Reputation: 9869

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

Upvotes: 7

Related Questions