Muhammad Adeel

Muhammad Adeel

  • NA
  • 55
  • 13.6k

Deleting an int value (C#)

Sep 13 2014 12:50 PM
I am trying to delete an int array element at the user input index and value (means replacing array element by the next one) so it is doing but in output it gives me the element twice example input array is : 1 2 3 4 5 6 and user says to delete 3rd element at 3 index then output is :1 2 4 4 5 6 what is the solution plz.


            Console.WriteLine("Enter The Length Of Linear Array");
            int length = Convert.ToInt32(Console.ReadLine());
            int[] LinearArr = new int[length + 2];
            Console.WriteLine("Maximum Number Of Inputs : {0}", length);


            for (int i = 1; i < LinearArr.Length - 1; i++)
            {
                LinearArr[i] = Convert.ToInt32(Console.ReadLine());
            }
                    Console.WriteLine("What Number You Want To Delete And At What Index");
                    int InsertNum2 = Convert.ToInt32(Console.ReadLine());
                    int k2 = Convert.ToInt32(Console.ReadLine());
                    Console.WriteLine("Number :{0} And Index :{1}",InsertNum2,k2);

                    InsertNum2 = LinearArr[k2];
                    for (int i = k2; i < LinearArr.Length-1; i++)
                    {
                        LinearArr[k2] = LinearArr[k2 + 1];


                    }
                    length = length - 1;
                    for (int i = 1; i < LinearArr.Length-1; i++)
                    {
                        Console.WriteLine(LinearArr[i]);
                    }
                   

Answers (1)