How to initializing IEnumerable<string> in C#

2 Answers

0 votes
using System;
using System.Collections.Generic;

class Program
{
    static void Main() {
        IEnumerable<string> iEnum = new List<string>() { "c#", "c", "c++", "java"};

        foreach (string s in iEnum) {
            Console.WriteLine(s);
        }
    }
}




/*
run:

c#
c
c++
java

*/

 



answered Aug 2, 2023 by avibootz
0 votes
using System;
using System.Collections.Generic;

class Program
{
    static void Main() {
        IEnumerable<string> iEnum = new string[] { "c#", "c", "c++", "java", "python" };

        foreach (string s in iEnum) {
            Console.WriteLine(s);
        }
    }
}




/*
run:

c#
c
c++
java
python

*/

 



answered Aug 2, 2023 by avibootz
...