简体   繁体   中英

Get the value from ListBox C#

I have the one Dictionary variable and Listbox.

Dictionary variable have the following values,

first
Second 

ListBox can have

first
Second
Third

Expected Output is : Third

Now I need the get the value from Listbox which is not available in the Dictionary?How to Compare the Listbox with Dictionary Value?

class Program
    {
        static void Main(string[] args)
        {
            List<string> list = new List<string>();
            list.Add("First");
            list.Add("second");
            list.Add("third");

            Dictionary<int, string> dictionary = new Dictionary<int, string>();

            dictionary.Add( 1,"First");
            dictionary.Add(2,"second");

            foreach (var li in list)
            {

                if (!dictionary.ContainsValue(li))
                {                  
                    Console.WriteLine(li);
                }
            }
            Console.ReadLine();
        }
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM