C# Programming, For Beginners, Learn Coding Fast! by Yao Ray

C# Programming, For Beginners, Learn Coding Fast! by Yao Ray

Author:Yao, Ray [Yao, Ray]
Language: eng
Format: epub
Publisher: Ray Yao 's eBooks & Books
Published: 2020-03-20T16:00:00+00:00


Access List Elements

The syntax to access List elements looks like this:

foreach (var elements in MyList) {

}

For Example:

using System;

using System. Collections. Generic;

namespace ListDemo{

class Program{

static void Main(string[] args){

List<int> MyList = new List<int> { 10, 11, 12, 13 };

foreach (var elements in MyList) { // access all elements

Console. Write(elements + " ");

}

Console. ReadLine();

}}}

Output: 10 11 12 13

Explanation:

“foreach (var elements in MyList){ }” accesses all elements in MyList, and put all values to the variable “elements”.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.