Search code examples
c#stringlistaddrange

Use AddRange for a new List<string>


How to: Use AddRange for a List

List<string> list = 
    new List<string>().AddRange(File.ReadAllLines(path, Encoding.UTF8);

It is a variable which is declared globally - what is my mistake?

The error is equal to

Converting from string to void is not allowed


Solution

  • You can simply change your code to this:

    List<string> list = new List<string>(File.ReadAllLines(path, Encoding.UTF8));