0
        int[] arry = { 23, 34,10, 11, 56 };
        int[] Output = { };
        
        for (int i = 0; i < arry.Length; i++)
        {
            int temp= arry[i];
            for (int j = 0; j < arry.Length; j++)
            {
                if (temp > arry[j] &&  Array.IndexOf(Output, temp)==-1)
                { 
                    temp = arry[j];

                }

                
            }
            Output[i] = temp;
        }

when I add temp to Output[] compiler return run time error "Index was outside the bounds of the array."

after slove Bubble Sort ...

int[] array = { 23, 34, 10, 11, 56,0,2 };

        for (int i = 0; i < array.Length-1 ; i++)
        {
            int temp;
            for (int j = 0; j < array.Length-1 ; j++)
            {
                if (array[j] > array[j + 1])
                {
                    temp = array[j];
                    array[j] = array[j + 1];
                    array[j + 1] = temp;

                }


            }


        }

        foreach (var item in array)
        {

            Console.WriteLine("Number:{0}", item);

        }
        Console.ReadKey();

thanks for Evry One

4
  • 1
    Output is a zero-length array, meaning that it has no slots for any data. Perhaps you want a generic list (List<int>) instead, and then you can use the list's .Add( ) method (e.g. myList.Add(temp);). Commented Mar 5, 2021 at 7:49
  • 2
    or var Output = new int[arry.Length] Commented Mar 5, 2021 at 7:52
  • Local variable should not start with a capital letter. var output please Commented Mar 5, 2021 at 7:53
  • TheGeneral thanks so much..Your Answer was Perfect.. Commented Mar 5, 2021 at 14:42

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.