Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

In C# How to correctly pass an int array to a function

how do I pass an array with an unknown number of integers to a function?
Can anybody tell me what I am doing wrong?

I get the following error when trying to run the code:

Error CS1501 No overload for method ‘Solution’ takes 6 arguments

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

using System;

namespace IntegerTest
{
    class Program
    {
        public static int Solution(int[] input)
        {
            Array.Sort(input);

            int index = 0;

            // Skip negatives
            while (index < input.Length && input[index] < 1)
                index++;

            int expected = 1;
            while (index < input.Length)
            {
                if (input[index] > expected)
                    return expected;

                // Skip number and all duplicates
                while (index < input.Length && input[index] == expected)
                    index++;

                expected++;
            }

            return expected;
        }

        public static void Main()
        {
            Console.WriteLine(Solution( 1, 3, 6, 4, 1, 2));

        }
    }

}
    

>Solution :

Your method accepts a int[], so create a new int[]

Solution(new int[] {1, 3, 6, 4, 1, 2});
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading