当前位置: 首页>>代码示例>>C#>>正文


C# ReadOnlyDictionary.TryGetValue方法代码示例

本文整理汇总了C#中ReadOnlyDictionary.TryGetValue方法的典型用法代码示例。如果您正苦于以下问题:C# ReadOnlyDictionary.TryGetValue方法的具体用法?C# ReadOnlyDictionary.TryGetValue怎么用?C# ReadOnlyDictionary.TryGetValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ReadOnlyDictionary的用法示例。


在下文中一共展示了ReadOnlyDictionary.TryGetValue方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ReadOnlyDictionaryWithStuffRetrievedTest

 public void ReadOnlyDictionaryWithStuffRetrievedTest()
 {
     var dictionary = new Dictionary<string, Tuple<string, Type, TimeSpan>>();
     var input = new Tuple<string, Type, TimeSpan>("John", typeof(string), new TimeSpan(0, 1, 0));
     dictionary.Add("John", input);
     ReadOnlyDictionary<string, Tuple<string, Type, TimeSpan>> target = new ReadOnlyDictionary<string, Tuple<string, Type, TimeSpan>>(dictionary);
     Assert.IsInstanceOfType(target, typeof(ReadOnlyDictionary<string, Tuple<string, Type, TimeSpan>>));
     var actual = new Tuple<string, Type, TimeSpan>("", typeof(string), new TimeSpan());
     target.TryGetValue("John", out actual);
     Assert.AreEqual(input, actual);
 }
开发者ID:nanderto,项目名称:PubSub,代码行数:11,代码来源:ReadOnlyDictionaryTest.cs

示例2: PopulateRuntimeTypes

        private static void PopulateRuntimeTypes(ReadOnlyDictionary<string, TypeDefinitionAst> parseTimeTypes, ReadOnlyDictionary<string, TypeDefinitionAst> runtimeTypes)
        {
            foreach (KeyValuePair<string, TypeDefinitionAst> parseTypePair in parseTimeTypes)
            {
                // We only need to populate types, if ASTs are not reused. Otherwise it's already populated.
                if (parseTypePair.Value.Type == null)
                {
                    TypeDefinitionAst typeDefinitionAst;
                    if (!runtimeTypes.TryGetValue(parseTypePair.Key, out typeDefinitionAst))
                    {
                        throw InterpreterError.NewInterpreterException(parseTypePair.Value, typeof(RuntimeException),
                            parseTypePair.Value.Extent,
                            "TypeNotFound", ParserStrings.TypeNotFound, parseTypePair.Value.Name);
                    }

                    parseTypePair.Value.Type = typeDefinitionAst.Type;
                }
            }
        }
开发者ID:40a,项目名称:PowerShell,代码行数:19,代码来源:Compiler.cs

示例3: TestReadOperations

        public void TestReadOperations()
        {
            var dic = new ReadOnlyDictionary<string, string>(new Dictionary<string, string>() {
            {"key1", "val1"},
            {"key2", "val2"},
            {"key3", "val3"},
              });

              Assert.AreEqual(3, dic.Count);

              Assert.AreEqual("val1", dic["key1"]);
              Assert.IsTrue(dic.Contains(new KeyValuePair<string, string>("key2", "val2")));
              Assert.IsTrue(dic.ContainsKey("key3"));

              foreach (var pair in dic) {
              }

              foreach (var key in dic.Keys) {
              }

              foreach (var val in dic.Values) {
              }

              var pairs = new KeyValuePair<string, string>[3];

              dic.CopyTo(pairs, 0);

              string outval = null;

              Assert.IsTrue(dic.TryGetValue("key1", out outval));
              Assert.AreEqual(outval, "val1");
        }
开发者ID:pengyancai,项目名称:cs-util,代码行数:32,代码来源:ReadOnlyDictionary.cs

示例4: ReadOnlyDictionary_Unit_TryGetValue_Optimal

        public void ReadOnlyDictionary_Unit_TryGetValue_Optimal()
        {
            IDictionary<String, String> dictionary = new Dictionary<String, String>() {
                { "Key1", "Value1" },
                { "Key2", "Value2" },
                { "Key3", "Value3" }
            };
            ReadOnlyDictionary<String, String> target = new ReadOnlyDictionary<String, String>(dictionary);
            String key = dictionary.Keys.First();
            String value;

            Boolean actual = target.TryGetValue(key, out value);
            Assert.AreEqual(true, actual);
            Assert.AreEqual(dictionary[key], value);
        }
开发者ID:cegreer,项目名称:Common,代码行数:15,代码来源:ReadOnlyDictionaryTests.cs

示例5: ReadOnlyDictionary_Unit_TryGetValue_KeyIsNull

        public void ReadOnlyDictionary_Unit_TryGetValue_KeyIsNull()
        {
            IDictionary<String, String> dictionary = new Dictionary<String, String>() {
                { "Key1", "Value1" },
                { "Key2", "Value2" },
                { "Key3", "Value3" }
            };
            ReadOnlyDictionary<String, String> target = new ReadOnlyDictionary<String, String>(dictionary);
            String key = null;
            String value;

            target.TryGetValue(key, out value);
        }
开发者ID:cegreer,项目名称:Common,代码行数:13,代码来源:ReadOnlyDictionaryTests.cs

示例6: ReadOnlyDictionary_Unit_TryGetValue_KeyDoesNotExist

        public void ReadOnlyDictionary_Unit_TryGetValue_KeyDoesNotExist()
        {
            IDictionary<String, String> dictionary = new Dictionary<String, String>() {
                { "Key1", "Value1" },
                { "Key2", "Value2" },
                { "Key3", "Value3" }
            };
            ReadOnlyDictionary<String, String> target = new ReadOnlyDictionary<String, String>(dictionary);
            String key = "MyKey";
            String value;

            Boolean actual = target.TryGetValue(key, out value);
            Assert.AreEqual(false, actual);
            Assert.IsNull(value);
        }
开发者ID:cegreer,项目名称:Common,代码行数:15,代码来源:ReadOnlyDictionaryTests.cs


注:本文中的ReadOnlyDictionary.TryGetValue方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。