I am given a string array and I have to create a new string array out of it with strings that are, say, less than 3 characters long. The problem is that I am not allowed to use lists, so everything has to be done with arrays.
So far I managed to filter the needed strings out of the array, but I dont know how to put them into a new array. Again, using lists is not allowed and it has to be a new array, so I cant modify the already existing one.
String[] string_array1 = new String[10] {"Monday", "Tue", "Wed", "Thu", "Fri", "Saturday", "Sunday", "Pizza Day", "Catt", "Garbage Day"};
Console.WriteLine(String.Join(", ", string_array1));
String[] string_array2 = new String[i];
for (int i = 0; i < string_array1.Length; i++)
{
if (string_array1[i].Length < 4)
{
Console.Write($"{string_array1[i]}" + " ");
}
}

List? does linq allowed? my concerns are, anarrayhas fixed size, whileListallows arbitrary length. if you insist on usingarray, you should find the number of elements that fulfil your criteria and then initialize the array for that size before finally filling the array up.String[] string_array2 = string_array1.Where(s => s.Length <= 3).ToArray()- No lists used.linq, before manifesting them into an array. i am curious whether op is doing some codility stuff or just daily use. if its codility thingy, op have to use iterations like the good old days.new String[10] {"Monday", "Tue", "Wed", "Thu", "Fri", "Saturday", "Sunday", "Pizza Day", "Catt", "Garbage Day"}input?