Console.Write("Enter the size of the array: "); string inputSize = Console.ReadLine(); int stringSize; int.TryParse(inputSize, out stringSize); string[] stringArray=new string[stringSize]; Console.WriteLine("Enter elements one by one\n"); for (int index = 0; index < stringSize; index++) { stringArray[index] = Console.ReadLine(); } Console.WriteLine("\n\nGiven Array\n"); foreach (string strings in stringArray) { Console.WriteLine(strings); } Console.Write("\nEnter String: "); string input = Console.ReadLine(); int TextIndex = Array.FindIndex(stringArray, m => m == input); Console.Write("\nRequired string index: {0}\n",TextIndex); int newSize=stringSize+1; Array.Resize(ref stringArray,newSize); int nIndex=TextIndex+1; while(nIndex>TextIndex) { if (nIndex < newSize) { stringArray[TextIndex + 1] = stringArray[TextIndex]; nIndex++; } break; } Console.Write("\nEnter new string: "); stringArray[TextIndex] = Console.ReadLine(); foreach(string newElements in stringArray) { Console.WriteLine(newElements); } Console.ReadLine();
If I'm not mistaken, I've solved 2-3 times similar kind of problem of yours.
System.Collections.Generic.Array<>
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)