If statements with Lists

Hey all, I have started to use Lists recently to save Quest variables, but I am having trouble finding out how to check if something exists (for an ‘if’ statement)
currently my code looks like this:

if (questHandler.questHolder.Exists(x => x.questName == questName))
					int num = this.convoLine;
					switch (num)

// (I have also created a list class here)
    using System;
    using UnityEngine;
    using System.Collections;
    using System.Collections.Generic;
    public class QuestHandler : MonoBehaviour
    	public string[] onQuests = {};
    	public string[] completedQuests = {"Mushrooms 1", "Mushrooms 2"};
    	public int mushKilled = 0;
    	public string questName;
    	public bool onQuest;
    	public bool cpltReq;
    	public List<QuestHandler> questHolder = new List<QuestHandler>();
    	public QuestHandler(string newQuestName, bool newOnQuest, bool newCpltReq)
    		questName = newQuestName;
    		onQuest = newOnQuest;
    		cpltReq = newCpltReq;
    	void Start()
            // Create a new member of List
    	questHolder.Add(new QuestHandler("Mushrooms 1", false, false));

Edit: Just remembered i should be more clear about what i want: How do I check if a certain part of a multi elemented (not sure what to call it) list exists? for example, for List[“quest”, true, true] how do i check if the first element is “quest”?

Basically you got the answer from Baste already. You have to use the list function “Exists” and create a lambda expression to check if the quest is active.

public bool IsQuestActive(string quest)
   return questHolder.Exists(q => q.questName == quest && q.onQuest == true);

Alternatively you use the list function “Find” and evaluate the quest object afterwards.

public bool IsQuestActive(string name)
   Quest quest = questHolder.Find(q => q.questName == name);
   return quest != null && quest.onQuest == true;

In general I have the feeling that you have a wrong understanding of what a generic list is. A list of type T only contains items of type T, nothing else. In your case the list only contains Quest objects. The Quest happens to have members like bools and strings, but that has nothing to do with the list itself. Hope that helped a bit? :slight_smile: