rbwhitaker / CSharpPlayersGuideEarlyAccess

A place to track issues with the C# Player's Guide for patches and future editions
18 stars 0 forks source link

Page 237, The modifier 'public' is not valid for this item #707

Closed Vladimir582 closed 1 year ago

Vladimir582 commented 1 year ago

Hello, when learning about generics lists, found exception (The modifier 'public' is not valid for this item) in a code, showed on Page 237, and don't know is it correct in a book or not.

In Errata I didn't found about this. Sinceresly, Vladimir.

PS, your book is great!

List<string> words = Repeat<string>("Alright", 3);
List<int> zeroes = Repeat<int>(0, 100);

public static List<T> Repeat<T>(T value, int times)
{
    List<T> collection = new List<T>();

    for (int index = 0; index < times; index++)
        collection.Add(value);

    return collection;
}
Vladimir582 commented 1 year ago

oh, i forget to put this method code into main generated list