Exemplo n.º 1
0
        public void GetValueOrDefaultWithFunc()
        {
            var dict = new Dictionary <int, int> {
                { 2, 4 }, { 3, 6 }
            };

            Assert.AreEqual(4, DictionaryUtility.GetValueOrDefault(dict, 2, () => - 2));
            Assert.AreEqual(-2, DictionaryUtility.GetValueOrDefault(dict, 1, () => - 2));
        }
        public void GetValueOrDefaultWithDefault()
        {
            Dictionary <int, int> dict = new Dictionary <int, int> {
                { 2, 4 }, { 3, 6 }
            };

            Assert.AreEqual(4, DictionaryUtility.GetValueOrDefault(dict, 2, -1));
            Assert.AreEqual(-1, DictionaryUtility.GetValueOrDefault(dict, 1, -1));
        }
Exemplo n.º 3
0
        public void GetValueOrDefaultWithDefault()
        {
            var dict = new Dictionary <int, int> {
                { 2, 4 }, { 3, 6 }
            };

#pragma warning disable CS0618 // Type or member is obsolete
            Assert.AreEqual(4, DictionaryUtility.GetValueOrDefault(dict, 2, -1));
            Assert.AreEqual(-1, DictionaryUtility.GetValueOrDefault(dict, 1, -1));
#pragma warning restore CS0618 // Type or member is obsolete
        }