I know this is a real low level question (I’m a beginner), but I got to know…
what is the best way to list all elements of an array?
I’m a little anal and always want to write the best code. I know we can write a function and pass the array and access every element using a for or foreach. but I have heard there is a better way for doing this. (something about lambda expressions)
Do you know how to do that?
>Solution :
Actually, there is a function for iterating through and array.
The concept of lambda expressions is a little advanced, so I don’t recommend learning it right now.(since you’re a beginner)
but you can use this syntax. It’s easy to use and handy:
static void Main(string[] args)
{
int[] someArray = { 1, 2, 3, 69, 4 };
Array.ForEach(someArray, element => Console.WriteLine(element));
}