Tuesday, September 22, 2015

Does a value exist in a dictionary in C#?

This test passes...

using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace Whatever.Tests
{
   [TestClass]
   public class DictionaryTests
   {
      [TestMethod]
      public void Test()
      {
         Dictionary<int, string> dictionary = new Dictionary<int, string>();
         dictionary.Add(13, "foo");
         dictionary.Add(42, "bar");
         dictionary.Add(69, "baz");
         dictionary.Add(88, "qux");
         Assert.AreEqual(dictionary.ContainsValue("foo"), true);
      }
   }
}

No comments:

Post a Comment