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


C# ReadOnlyDictionary.ContainsKey方法代码示例

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


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

示例1: ConstructorKeySelector

        public void ConstructorKeySelector()
        {
            var dict = new ReadOnlyDictionary<int, DateTime> (new[]{
                new DateTime (2009, 1, 1),
                new DateTime (2008, 1, 1),
                new DateTime (2007, 1, 1)
            }.ToDictionary(d => d.Year));

            Assert.IsTrue (dict.ContainsKey (2009));
            Assert.IsTrue (dict.ContainsKey (2008));
            Assert.IsTrue (dict.ContainsKey (2007));
        }
开发者ID:mono,项目名称:rocks,代码行数:12,代码来源:ReadOnlyDictionaryTest.cs

示例2: TestConstructBaseDictionaryChanged

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

              Assert.IsTrue(dic.IsReadOnly);
              Assert.IsTrue(dic.ContainsKey("key1"));
              Assert.IsFalse(dic.ContainsKey("key4"));

              basedic.Add("key4", "val4");

              Assert.IsTrue(dic.ContainsKey("key4"));
        }
开发者ID:pengyancai,项目名称:cs-util,代码行数:17,代码来源:ReadOnlyDictionary.cs

示例3: GetNextExp

		/// <summary>
		/// 次のレベルに上がるのに必要な経験値の量を取得します。
		/// </summary>
		/// <param name="expTable">経験値テーブル。</param>
		/// <param name="current">現在の累積経験値。</param>
		private static int GetNextExp( ReadOnlyDictionary<int, Experience> expTable, int current ) {

			Experience l = expTable.Values.FirstOrDefault( e => e.Total + e.Next > current );

			if ( l == null || !expTable.ContainsKey( l.Level + 1 ) )
				return 0;

			return expTable[l.Level + 1].Total - current;
		}
开发者ID:silfumus,项目名称:ElectronicObserver,代码行数:14,代码来源:ExpTable.cs

示例4: TryAdd

 private static void TryAdd(ReadOnlyDictionary<string, string> dictionary, List<string> parts, string key)
 {
     if (dictionary.ContainsKey(key))
         parts.Add(dictionary[key]);
 }
开发者ID:johanclasson,项目名称:Akkomation,代码行数:5,代码来源:IdConverter.cs

示例5: ThrowIfNotFound

 public static void ThrowIfNotFound(ReadOnlyDictionary<string, string> dictionary, string data, string key)
 {
     if (dictionary.ContainsKey(key))
         return;
     throw new KeyNotFoundException($"The key '{key}' is missing in '{data}'");
 }
开发者ID:johanclasson,项目名称:Akkomation,代码行数:6,代码来源:IdConverter.cs

示例6: TryMinifyNumberWithUnit

        private static void TryMinifyNumberWithUnit(NumberWithUnitValue value, ReadOnlyDictionary<Unit, decimal> possibleConversions, ref NumberWithUnitValue smallest)
        {
            if (!possibleConversions.ContainsKey(value.Unit)) return;

            var min = MinifyNumberValue(value);

            var ret = new NumberWithUnitValue(min.Value, value.Unit);
            string retStr;
            using (var buffer = new StringWriter())
            {
                ret.Write(buffer);
                retStr = buffer.ToString();
            }

            var inBasic = min.Value * possibleConversions[value.Unit];

            foreach (var unit in possibleConversions.Keys)
            {
                var conversion = possibleConversions[unit];

                var maxPrecision = inBasic / conversion;

                // 5 decimal points seems like an acceptable level of precision; webkit seems to agree
                var inUnit = decimal.Round(maxPrecision, 5);

                var asNum = new NumberValue(inUnit);
                var minified = MinifyNumberValue(asNum);

                var newMin = new NumberWithUnitValue(minified.Value, unit);
                string newMinStr;

                using (var buffer = new StringWriter())
                {
                    newMin.Write(buffer);
                    newMinStr = buffer.ToString();
                }

                if (newMinStr.Length < retStr.Length)
                {
                    ret = newMin;
                    retStr = newMinStr;
                }
            }

            smallest = ret;
        }
开发者ID:kevin-montrose,项目名称:More,代码行数:46,代码来源:Minify.cs

示例7: key_correlator_replay

    IDisposable key_correlator_replay(DDS.DomainParticipant participant, bool useLinq)
    {
        int MAX_COLORS = 8;

        var rx_square_reader =
        DDSObservable.FromKeyedTopic<string, ShapeTypeExtended>(participant, "Square", shape => shape.color);

        var dictionary = new Dictionary<string, string>();
        dictionary.Add("PURPLE", "BLUE");
        dictionary.Add("RED", "GREEN");
        dictionary.Add("YELLOW", "CYAN");
        dictionary.Add("MAGENTA", "ORANGE");

        var associations = new ReadOnlyDictionary<string, string>(dictionary);

        var cache = rx_square_reader.Replay();
        cache.Connect();

        if (useLinq)
        {
          return
          (from group1 in cache.Where(groupedSq => associations.ContainsKey(groupedSq.Key))
           from group2 in cache.Take(MAX_COLORS)
           where associations[group1.Key] == group2.Key
           select new { k1 = group1, k2 = group2 })
            .Subscribe(pair =>
            {
              Console.WriteLine("MATCH {0}--{1}", pair.k1.Key, pair.k2.Key);
              pair.k1.CombineLatest(pair.k2,
                                   (a, b) =>
                                   {
                                     return new ShapeTypeExtended
                                     {
                                       x = (int)((a.x + b.x) / 2),
                                       y = (int)((a.y + b.y) / 2),
                                       color = a.color,
                                       shapesize = a.shapesize
                                     };
                                   })
                     .Subscribe(triangle_writer);
            });
        }
        else
        {
          return
        cache
           .Where(groupedSq => associations.ContainsKey(groupedSq.Key))
           .SelectMany(groupedSq => cache.Take(MAX_COLORS),
                      (groupedSq, cached_groupedSq) =>
                      {
                        if (associations[groupedSq.Key] == cached_groupedSq.Key)
                        {
                          Console.WriteLine("MATCH {0} -- {1}", groupedSq.Key, cached_groupedSq.Key);
                          groupedSq
                            .CombineLatest(cached_groupedSq,
                                          (a, b) =>
                                          {
                                            return new ShapeTypeExtended
                                            {
                                              x = (int)((a.x + b.x) / 2),
                                              y = (int)((a.y + b.y) / 2),
                                              color = a.color,
                                              shapesize = a.shapesize
                                            };
                                          })
                            .Subscribe(triangle_writer);
                        }
                        else
                          Console.WriteLine("NO-MATCH {0} -- {1}", groupedSq.Key, cached_groupedSq.Key);

                        return (IGroupedObservable<string, ShapeTypeExtended>)groupedSq;
                      }).Subscribe();
        }
    }
开发者ID:kharesp,项目名称:rticonnextdds-reactive,代码行数:74,代码来源:rxddstest.cs

示例8: GetExpToLevel

		/// <summary>
		/// 指定したレベルに上がるのに必要な経験値の量を取得します。
		/// </summary>
		/// <param name="expTable">経験値テーブル。</param>
		/// <param name="current">現在の累積経験値。</param>
		/// <param name="level">対象のレベル。</param>
		private static int GetExpToLevel( ReadOnlyDictionary<int, Experience> expTable, int current, int level ) {

			if ( !expTable.ContainsKey( level ) )
				return 0;

			return expTable[level].Total - current;
		}
开发者ID:silfumus,项目名称:ElectronicObserver,代码行数:13,代码来源:ExpTable.cs

示例9: GetFileInfo

		private static FileInfo[] GetFileInfo(ReadOnlyDictionary<long, ReadOnlyCollection<FileInfo>> names, long awbId)
		{
			return names != null && names.ContainsKey(awbId) ? names[awbId].ToArray() : null;
		}
开发者ID:UHgEHEP,项目名称:test,代码行数:4,代码来源:AwbPresenter.cs

示例10: NotifySignals

        /// <summary>
        /// Takes a snapshot of the child signals before making a change, then makes the change, then takes another
        /// snapshot, does a comparison, and fires a signal changed event for any signals that are different.
        /// </summary>
        /// <param name="act">Action that does changes to the tree</param>
        public void NotifySignals(Action act)
        {
            var oldChildren = new ReadOnlyDictionary<FieldGuid, NodeBase>(new Dictionary<FieldGuid, NodeBase>());
            if (Node != null)
            {
                oldChildren = Node.GetChildrenRecursive();
            }

            act();

            var newChildren = new ReadOnlyDictionary<FieldGuid, NodeBase>(new Dictionary<FieldGuid, NodeBase>());
            if (Node != null)
            {
                newChildren = Node.GetChildrenRecursive();
            }

            foreach (var newChildKey in newChildren.Keys)
            {
                if (!oldChildren.ContainsKey(newChildKey))
                {
                    // it's an edited node
                    var sig = newChildren[newChildKey] as NodeSignal;
                    runtimeService.NotifySignalChanged(sig);
                }
            }
        }
开发者ID:EdWeller,项目名称:SoapboxSnap,代码行数:31,代码来源:AbstractEditorItem.cs

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

示例12: ReadOnlyDictionary_Unit_ContainsKey_Optimal

        public void ReadOnlyDictionary_Unit_ContainsKey_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();

            Boolean actual = target.ContainsKey(key);
            Assert.AreEqual(true, actual);
        }
开发者ID:cegreer,项目名称:Common,代码行数:13,代码来源:ReadOnlyDictionaryTests.cs

示例13: ReadOnlyDictionary_Unit_ContainsKey_KeyIsNull

        public void ReadOnlyDictionary_Unit_ContainsKey_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;

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

示例14: ReadOnlyDictionary_Unit_ContainsKey_KeyDoesNotExist

        public void ReadOnlyDictionary_Unit_ContainsKey_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";

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


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