Answer to Question #345356 in C# for kanni

Question #345356

. Create a generic collection that stores even numbers from 2 to 20.



Display only the first element of the List.




1
Expert's answer
2022-05-26T16:56:59-0400
using System;
using System.Collections.Generic;
using System.Linq;
class Program
{
    static void Main(string[] args)
    {
        List<int> numbers = new List<int>();
        for (int i = 2; i <= 20; i++)
            if (i % 2 == 0)
                numbers.Add(i);
        Console.WriteLine(numbers.First());
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS