0

Summary:

For my business class, we have to develop a product and/or service. I'm trying to develop a solution for other groups to help them manage their inventory. I've already got one working in Python, however, C# makes developing GUI easier (Thank you, Visual Studio). I'm having difficulties with a list of lists.


Resources Previously checked:

Creating a List of Lists in C#

List(T) Class


Variables In Use:

int timesRan = 0;
private List<List<String>> itemList = new List<List<String>>();

Code In Use:

    do
    {
        timesRan++;
        itemList[timesRan - 1].contains(SearchName.Text);

    } while (timesRan < itemList.Count);

Question:

When I do this, the IDE (Visual Studio Community 2017) tells me " 'List' does not contain a definition for 'Contains' and no extension method accepting a first argument of type 'List' could be found". So how do I check if the list at the index contains a given string? Have I overlooked something in the resources I checked?

John Smith
  • 97
  • 9
  • Have you tried itemList[timesRan - 1].Contains(SearchName.Text) with a capital C? – Mick Jul 26 '18 at 02:24
  • what do you want for `itemList[timesRan - 1].Contains(SearchName.Text);`. it is just a condition, which return true or false in C# – SKLTFZ Jul 26 '18 at 02:27
  • The reasoning behind it is in order to allow people who use this the chance to search the entries they make and correct them if they've made an input error. The reason for the while loop is to check each list in the list, and pull the information from that list and present it to the user in a friendly(-ish) way. – John Smith Jul 26 '18 at 02:28
  • Why do you need `List>`? You just need `List` based on your scenario. What do you want to do after you find the text? – Win Jul 26 '18 at 02:29
  • @win thats what i was thinking – fuzzybear Jul 26 '18 at 02:29
  • And I made a typo and forgot to capitalize the C. Somehow I thought it'd be something really simple in answer. Thanks all for the help. And is that a decent way of formatting a stackoverflow question? (New to this) – John Smith Jul 26 '18 at 02:31
  • And also, I do actually need the `List>` in this. – John Smith Jul 26 '18 at 02:32

1 Answers1

1

I think you passed the parameter incorrectly,in addition, please add the namespace

using System.Collections.Generic; at the top of the file.

This code should be fine

        int timesRan = 0;
        var itemList = new List<List<string>>();

       bool hasText = itemList[0].Contains("Hello world");
Toan Nguyen
  • 11,263
  • 5
  • 43
  • 59