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


C# ReadOnlyDictionary.CopyTo方法代码示例

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


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

示例1: ReadOnlyDictionary_Unit_CopyTo_Optimal

        public void ReadOnlyDictionary_Unit_CopyTo_Optimal()
        {
            IDictionary<String, String> dictionary = new Dictionary<String, String>() {
                { "Key1", "Value1" },
                { "Key2", "Value2" },
                { "Key3", "Value3" }
            };
            ReadOnlyDictionary<String, String> target = new ReadOnlyDictionary<String, String>(dictionary);
            KeyValuePair<String, String>[] array = new KeyValuePair<String, String>[dictionary.Count];
            Int32 arrayIndex = 0;

            target.CopyTo(array, arrayIndex);
            Assert.AreEqual(dictionary.Count, array.Length);
            foreach (KeyValuePair<String, String> pair in array) {
                Assert.IsTrue(dictionary.Contains(pair));
            }
        }
开发者ID:cegreer,项目名称:Common,代码行数:17,代码来源:ReadOnlyDictionaryTests.cs

示例2: 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

示例3: ReadOnlyDictionary_Unit_CopyTo_ArrayIsTooSmall

        public void ReadOnlyDictionary_Unit_CopyTo_ArrayIsTooSmall()
        {
            IDictionary<String, String> dictionary = new Dictionary<String, String>() {
                { "Key1", "Value1" },
                { "Key2", "Value2" },
                { "Key3", "Value3" }
            };
            ReadOnlyDictionary<String, String> target = new ReadOnlyDictionary<String, String>(dictionary);
            KeyValuePair<String, String>[] array = new KeyValuePair<String, String>[dictionary.Count - 2];
            Int32 arrayIndex = 1;

            target.CopyTo(array, arrayIndex);
        }
开发者ID:cegreer,项目名称:Common,代码行数:13,代码来源:ReadOnlyDictionaryTests.cs


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