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?

7
  • Have you tried itemList[timesRan - 1].Contains(SearchName.Text) with a capital C? Commented Jul 26, 2018 at 2:24
  • what do you want for itemList[timesRan - 1].Contains(SearchName.Text);. it is just a condition, which return true or false in C# Commented Jul 26, 2018 at 2: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. Commented Jul 26, 2018 at 2:28
  • Why do you need List<List<String>>? You just need List<string> based on your scenario. What do you want to do after you find the text? Commented Jul 26, 2018 at 2:29
  • @win thats what i was thinking Commented Jul 26, 2018 at 2:29

1 Answer 1

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");
Sign up to request clarification or add additional context in comments.

1 Comment

Sorry for forgetting to add that information, thank you for reminding me.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.