Adventures of a wannabe geek!

Ranting within

How-to-Create-and-Fill-and-IEnumerable

Very simple tip i found at DevEvening tonight from Mark Rendle

To create a new IEnumerable<string> and add items to that IEnumerable<string> then something very small along the lines of:

        private static IEnumerable GetStrings()
        {
            yield return "a";
            yield return "b";
            yield return "c";
            yield return "d";
            yield return "e";
            yield return "f";
            yield return "g";
            yield return "h";
            yield return "i";
            yield return "j";
            yield return "k";
            yield return "l";
            yield return "m";
            yield return "n";
        }

I’m sure most of you knew this but it was never something i knew how to do. i usually ended up doing something along the lines of

        private static IEnumerable ConvertListToIEnumberable()
        {
            var> listStrings = new List();
            listStrings.Add("a");
            listStrings.Add("b");
            listStrings.Add("c");
            listStrings.Add("d");
            listStrings.Add("e");

            IEnumerable ienumString = listStrings;
            return ienumString;
        }

Possibly useful to you, possibly not as you may already know it :)