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


C# Dictionary.Contains方法代码示例

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


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

示例1: btnStart_Click

        private void btnStart_Click(object sender, RoutedEventArgs e)
        {
            Task.Run(async () =>
            {
                bool isOpened = await this.tmp102.OpenAsync();

                IDictionary bag = new Dictionary<SensorType, float>();

                while (true)
                {
                    float temperature = tmp102.Temperature();
                    SensorType sensorType = SensorType.Temperature;

                    if (!bag.Contains(sensorType))
                        bag.Add(sensorType, temperature);
                    else
                        bag[sensorType] = temperature;

                    if ((this.iotClient != null) && (this.iotClient.IsOpen))
                    {
                        this.iotClient.SendAsync(bag);
                    }

                    await Task.Delay(5000);
                }
            });

        }
开发者ID:Mecabot,项目名称:pi2toeventhubs,代码行数:28,代码来源:MainPage.xaml.cs

示例2: btnStart_Click

        private void btnStart_Click(object sender, RoutedEventArgs e)
        {
            Task.Run(async () =>
            {
                IDictionary bag = new Dictionary<SensorType, float>();
                var rnd = new Random();

                while (true)
                {

                    var temperature = (float)GetRandomNumber(rnd, -10, 50);

                    SensorType sensorType = SensorType.Temperature;

                    if (!bag.Contains(sensorType))
                        bag.Add(sensorType, temperature);
                    else
                        bag[sensorType] = temperature;

                    if ((this.iotClient != null) && (this.iotClient.IsOpen))
                    {
                        this.iotClient.SendAsync(bag);
                    }

                    await Task.Delay(5000);
                }
            });
        }
开发者ID:JimmyBcn,项目名称:IoTSpike,代码行数:28,代码来源:MainPage.xaml.cs

示例3: WriterWriteEmptyString

        public void WriterWriteEmptyString()
        {
            string outputPath = Guid.NewGuid().ToString() + ".plist";

            IDictionary dict = new Dictionary<string, object>();
            dict["Empty"] = string.Empty;

            BinaryPlistWriter writer = new BinaryPlistWriter();
            writer.WriteObject(outputPath, dict);

            BinaryPlistReader reader = new BinaryPlistReader();
            dict = reader.ReadObject(outputPath);

            Assert.IsTrue(dict.Contains("Empty"));
            Assert.AreEqual(string.Empty, dict["Empty"]);
        }
开发者ID:ChadBurggraf,项目名称:plists-cs,代码行数:16,代码来源:WriterTests.cs

示例4: Run

        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            // 
            // TODO: Insert code to start one or more asynchronous methods 
            //

            BackgroundTaskDeferral deferral = taskInstance.GetDeferral();

            this.tmp102 = new TMP102();

            // set and open the IoT client
            if (this.iotClient == null)
            {
                //this.iotClient = new IoTClient("raspberrypi2", Guid.NewGuid().ToString(), this.connectionString, this.eventHubEntity);
                this.iotClient = new IoTClientConnectTheDots("raspberrypi2", Guid.NewGuid().ToString(), this.connectionString, this.eventHubEntity);
            }

            if (!this.iotClient.IsOpen)
                this.iotClient.Open();


            bool isOpened = await this.tmp102.OpenAsync();
            
            IDictionary bag = new Dictionary<SensorType, float>();

            while (true)
            {
                float temperature = tmp102.Temperature();
                SensorType sensorType = SensorType.Temperature;

                if (!bag.Contains(sensorType))
                    bag.Add(sensorType, temperature);
                else
                    bag[sensorType] = temperature;

                if ((this.iotClient != null) && (this.iotClient.IsOpen))
                {
                    this.iotClient.SendAsync(bag);
                }

                await Task.Delay(5000);
            }

            deferral.Complete();
        }
开发者ID:Mecabot,项目名称:pi2toeventhubs,代码行数:45,代码来源:StartupTask.cs

示例5: IDictionary_Contains

		public void IDictionary_Contains ()
		{
			IDictionary d = new Dictionary<int, int> ();
			d.Add (1, 2);
			Assert.IsTrue (d.Contains (1));
			Assert.IsFalse (d.Contains (2));
			Assert.IsFalse (d.Contains ("x"));
		}
开发者ID:t-ashula,项目名称:mono,代码行数:8,代码来源:DictionaryTest.cs

示例6: Execute

        /// <summary>
        /// Execute the MSBuild Task.
        /// </summary>
        /// <returns></returns>
        public override bool Execute()
        {
            _modifiedFiles = new ArrayList();
            _deletedFiles = new ArrayList();

            // Parse local manifest to retrieve list of files and their hashes.
            string[] localManifest = File.ReadAllLines(_localManifestFile);
            Dictionary<string, string> localFiles = new Dictionary<string,string>();
            for (int i = 0; i < localManifest.Length; i++)
            {
                if (localManifest[i].StartsWith("Archive-Asset-Name: "))
                {
                    string assetName = localManifest[i].Substring(20);
                    i++;
                    if (localManifest[i].StartsWith("Archive-Asset-SHA-512-Digest: "))
                    {
                        string assetHash = localManifest[i].Substring(30);
                        localFiles.Add(assetName, assetHash);
                    }
                    else
                    {
                        return false;
                    }
                }
            }

            // Do the same for the target manifest.
            string[] targetManifest = File.ReadAllLines(_targetManifestFile);
            Dictionary<string, string> targetFiles = new Dictionary<string,string>();
            for (int i = 0; i < targetManifest.Length; i++)
            {
                if (targetManifest[i].StartsWith("Archive-Asset-Name: "))
                {
                    string assetName = targetManifest[i].Substring(20);
                    i++;
                    if (targetManifest[i].StartsWith("Archive-Asset-SHA-512-Digest: "))
                    {
                        string assetHash = targetManifest[i].Substring(30);
                        targetFiles.Add(assetName, assetHash);
                    }
                    else
                    {
                        return false;
                    }
                }
            }

            // Compare hashes and populate the lists of modified and deleted files.
            string[] targetFileMap = File.ReadAllLines(_targetFileMap);
            foreach (KeyValuePair<string, string> file in localFiles)
            {
                // For some reason this MANIFEST.bbr file appears in the manifest, even though
                // it doesn't actually exist anywhere...?  It doesn't seem to correspond to
                // MANIFEST.MF either.
                if (file.Key == "META-INF/MANIFEST.bbr")
                {
                    continue;
                }

                // If the target manifest doesn't contain the same key/value pair,
                // that means the local file has been either added or modified.
                if (!targetFiles.Contains(file))
                {
                    TaskItem item = new TaskItem(file.Key);
                    item.SetMetadata("SourcePath", getSourcePath(file.Key, targetFileMap));
                    _modifiedFiles.Add(item);
                }
            }

            IDictionaryEnumerator targetEnum = targetFiles.GetEnumerator();
            while (targetEnum.MoveNext())
            {
                // If the local manifest doesn't contain the same key,
                // that means the target file has been deleted from the project.
                if (!localFiles.ContainsKey((string)targetEnum.Key))
                {
                    TaskItem item = new TaskItem((string)targetEnum.Key);
                    _deletedFiles.Add(item);
                }
            }

            // For some reason the manifest file doesn't show up in the target file map
            // or the manifest itself, so we add it manually here and always upload it.
            TaskItem manifestItem = new TaskItem("META-INF/MANIFEST.MF");
            manifestItem.SetMetadata("SourcePath", "localManifest.mf");
            _modifiedFiles.Add(manifestItem);

            return true;
        }
开发者ID:blackberry,项目名称:VSPlugin,代码行数:93,代码来源:DiffManifests.cs

示例7: Contains_Enumerable_OnDictionary_IsTranslatedAsAContainsResultOperator

    public void Contains_Enumerable_OnDictionary_IsTranslatedAsAContainsResultOperator ()
    {
      var dictionary = new Dictionary<string, int>();
      var query = from c in QuerySource
                  where dictionary.Contains (new KeyValuePair<string, int> (c.Name, c.ID))
                  select c;

      var queryModel = QueryParser.GetParsedQuery (query.Expression);

      var whereClause = (WhereClause) queryModel.BodyClauses.Single ();
      Assert.That (whereClause.Predicate, Is.InstanceOf<SubQueryExpression> ());

      var subQueryModel = ((SubQueryExpression) whereClause.Predicate).QueryModel;
      Assert.That (subQueryModel.ResultOperators, Has.Count.EqualTo (1));
      Assert.That (subQueryModel.ResultOperators.Single(), Is.TypeOf<ContainsResultOperator>());
    }
开发者ID:hong1990,项目名称:Relinq,代码行数:16,代码来源:ResultOperatorQueryParserIntegrationTest.cs

示例8: Contains_IDictionary_IsNotTranslatedAsAContainsResultOperator

    public void Contains_IDictionary_IsNotTranslatedAsAContainsResultOperator ()
    {
      IDictionary dictionary = new Dictionary<string, int> ();
      var query = from c in QuerySource
                  where dictionary.Contains (c.Name)
                  select c;

      var queryModel = QueryParser.GetParsedQuery (query.Expression);

      var whereClause = (WhereClause) queryModel.BodyClauses.Single();
      Assert.That (whereClause.Predicate, Is.Not.InstanceOf<SubQueryExpression> ());
      Assert.That (whereClause.Predicate, Is.InstanceOf<MethodCallExpression> ());
    }
开发者ID:hong1990,项目名称:Relinq,代码行数:13,代码来源:ResultOperatorQueryParserIntegrationTest.cs

示例9: ReadOnlyDictionary_Unit_GetEnumerator1_Optimal

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

            using (IEnumerator<KeyValuePair<String, String>> actual = target.GetEnumerator()) {
                Int32 count = 0;
                while (actual.MoveNext()) {
                    count++;
                    Assert.IsTrue(dictionary.Contains(actual.Current));
                }
                Assert.AreEqual(dictionary.Count, count);
            }
        }
开发者ID:cegreer,项目名称:Common,代码行数:18,代码来源:ReadOnlyDictionaryTests.cs

示例10: SendData

        private void SendData()
        {
            Task.Run(() =>
            {
                IDictionary bag = new Dictionary<SensorType, float>();

                var rate = (float)currentRate;

                SensorType sensorType = SensorType.Temperature;

                if (!bag.Contains(sensorType))
                    bag.Add(sensorType, rate);
                else
                    bag[sensorType] = rate;

                if ((this.iotClient != null) && (this.iotClient.IsOpen))
                {
                    this.iotClient.SendAsync(bag);
                }
            });
        }
开发者ID:JimmyBcn,项目名称:IoTSpike,代码行数:21,代码来源:MainPage.xaml.cs

示例11: ShouldLog_IfExceptionDataContainsLoggedByOfIncompatibleType_ReturnsTrue

        public void ShouldLog_IfExceptionDataContainsLoggedByOfIncompatibleType_ReturnsTrue()
        {
            // Arrange
            Mock<ExceptionLogger> mock = new Mock<ExceptionLogger>();
            mock.CallBase = true;
            ExceptionLogger product = mock.Object;

            IDictionary data = new Dictionary();
            data.Add(ExceptionLogger.LoggedByKey, null);
            Exception exception = CreateException(data);
            ExceptionLoggerContext context = CreateMinimalValidLoggerContext(exception);

            // Act
            bool shouldLog = product.ShouldLog(context);

            // Assert
            Assert.Equal(true, shouldLog);
            Assert.True(data.Contains(ExceptionLogger.LoggedByKey));
            object updatedLoggedBy = data[ExceptionLogger.LoggedByKey];
            Assert.Null(updatedLoggedBy);
        }
开发者ID:huangw-t,项目名称:aspnetwebstack,代码行数:21,代码来源:ExceptionLoggerTests.cs

示例12: ShouldLog_IfExceptionDataContainsLoggedByLogger_ReturnsFalse

        public void ShouldLog_IfExceptionDataContainsLoggedByLogger_ReturnsFalse()
        {
            // Arrange
            Mock<ExceptionLogger> mock = new Mock<ExceptionLogger>();
            mock.CallBase = true;
            ExceptionLogger product = mock.Object;

            IDictionary data = new Dictionary();
            ICollection<object> loggedBy = new List<object>() { product };
            data.Add(ExceptionLogger.LoggedByKey, loggedBy);
            Exception exception = CreateException(data);
            ExceptionLoggerContext context = CreateMinimalValidLoggerContext(exception);

            // Act
            bool shouldLog = product.ShouldLog(context);

            // Assert
            Assert.Equal(false, shouldLog);
            Assert.True(data.Contains(ExceptionLogger.LoggedByKey));
            object updatedLoggedBy = data[ExceptionLogger.LoggedByKey];
            Assert.Same(loggedBy, updatedLoggedBy);
            Assert.Equal(1, loggedBy.Count);
        }
开发者ID:huangw-t,项目名称:aspnetwebstack,代码行数:23,代码来源:ExceptionLoggerTests.cs

示例13: ShouldLog_IfExceptionDataIsEmpty_AddsLoggedByKeyWithLoggerValueAndReturnsTrue

        public void ShouldLog_IfExceptionDataIsEmpty_AddsLoggedByKeyWithLoggerValueAndReturnsTrue()
        {
            // Arrange
            Mock<ExceptionLogger> mock = new Mock<ExceptionLogger>();
            mock.CallBase = true;
            ExceptionLogger product = mock.Object;

            IDictionary data = new Dictionary();
            Exception exception = CreateException(data);
            ExceptionLoggerContext context = CreateMinimalValidLoggerContext(exception);

            // Act
            bool shouldLog = product.ShouldLog(context);

            // Assert
            Assert.Equal(true, shouldLog);
            Assert.True(data.Contains(ExceptionLogger.LoggedByKey));
            object loggedBy = data[ExceptionLogger.LoggedByKey];
            Assert.IsAssignableFrom<ICollection<object>>(loggedBy);
            Assert.Contains(product, (ICollection<object>)loggedBy);
        }
开发者ID:huangw-t,项目名称:aspnetwebstack,代码行数:21,代码来源:ExceptionLoggerTests.cs

示例14: NonNullDictionary_Unit_GetEnumerator3_Optimal

        public void NonNullDictionary_Unit_GetEnumerator3_Optimal()
        {
            IDictionary<String, String> dictionary = new Dictionary<String, String>() {
                { "Key1", "Value1" },
                { "Key2", "Value2" },
                { "Key3", "Value3" }
            };
            IEnumerable target = new NonNullDictionary<String, String>(dictionary);

            IEnumerator actual = target.GetEnumerator();
            Int32 count = 0;
            while (actual.MoveNext()) {
                count++;
                Assert.IsTrue(dictionary.Contains((KeyValuePair<String, String>)actual.Current));
            }
            Assert.AreEqual(dictionary.Count, count);
        }
开发者ID:cegreer,项目名称:Common,代码行数:17,代码来源:NonNullDictionaryTests.cs

示例15: NonNullDictionary_Unit_CopyTo_Optimal

        public void NonNullDictionary_Unit_CopyTo_Optimal()
        {
            IDictionary<String, String> dictionary = new Dictionary<String, String>() {
                { "Key1", "Value1" },
                { "Key2", "Value2" },
                { "Key3", "Value3" }
            };
            ICollection<KeyValuePair<String, String>> target = new NonNullDictionary<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,代码来源:NonNullDictionaryTests.cs


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