Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

List all elements of array

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

static void Main(string[] args)    
{    
    int[] someArray = { 1, 2, 3, 69, 4 };    
    Array.ForEach(someArray, element => Console.WriteLine(element));    
}    
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading