Using ForEach to write an array instead of a List <T> - CSharp Language Basics

CSharp examples for Language Basics:Array

Description

Using ForEach to write an array instead of a List <T>

Demo Code



using System;//from   w w w .  j  a  v a2  s.  c o  m
using System.Collections.Generic;

class Program
{
    static void Main(string[] args)
    {
        List<int> numbers = new List<int>() { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 };
        int[] numArray = numbers.ToArray();
        
        // Convert the int list to an array:
        Array.ForEach(numArray, n => Console.Write("{0}, ", n.ToString()));
    }
}

Result


Related Tutorials