0

So, I'm working with c# and I'm trying to create a Bar graph in the console using strings. So I created a 2D list and gave each slot a default "empty" image.

List<List<string>> chart = new List<List<string>>() {"| |"};

but when i wrote it out, i got these two error messages in Visual studios

Error   1   Argument 1: cannot convert from 'string' to 'System.Collections.Generic.List<string>'

Error   2   The best overloaded Add method 'System.Collections.Generic.List<System.Collections.Generic.List<string>>.Add(System.Collections.Generic.List<string>)' for the collection initializer has some invalid arguments
2
  • 1
    Probably what you are looking for is List<string> not List<List<String>> Commented Mar 27, 2015 at 7:03
  • int[] levels = { 1, 4, 5, 2 }; Console.Write(string.Join("\r\n", Enumerable.Range(levels.Min(), levels.Max()).Reverse().Select(y => string.Join(" ", levels.Select(l => l >= y ? "|" : " "))))); Commented Mar 27, 2015 at 7:26

3 Answers 3

1

The right syntax is

List<List<string>> chart = new List<List<string>>() { new List<String>() { "| |" }};

since you're creating list of list of string (2D list as you've put it), not just list of string.

Sign up to request clarification or add additional context in comments.

Comments

0

When u need to create default string in your List try this:

List<string> chart = new List<string>() {"| |"};

or if u need initialize default string in your List of List<string> try

List<List<string>> chart = new List<List<string>>() { new List<string> { "| |" } };

Comments

0

You need to add List as parameter

List<List<string>> chart = new List<List<string>>() { new List<string>{"| |","| |"}};

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.