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 we give input as "one" "two" "three" "five" "six" We should add "four" at runtime and add it in the array and array size size gets incremented. Then the resulting array should be "one" "two" "three" "four" "five" "six"
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)