I am new to programming. While learning the data structure Array, I came to know that we have to initialize the array with the size, while creating one. But I also saw a code snippet in one of the sites which i make use to learn coding. The code is as follows
int[] ar = Array.ConvertAll(Console.ReadLine().Split(' '), arTemp => Convert.ToInt32(arTemp))
I guess the code is to read the input from the console(which is a string) and splits it into substrings and then convert into integer array and gets stored in 'ar'.
My question is that there were no errors on this line. But the array size is not mentioned before using them. How is that? where do the size of this array gets initialized in this case?
From MSDN:
In
Array.ConvertAll()static function, Size array is based on your input array.In your case input array is
Console.ReadLine().Split(' ').Split(' ')returns an array of space seperated words. Size of this array get assigned to the output ofArray.ConvertAll()function