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


C# ObservableDictionary.TryRemove方法代码示例

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


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

示例1: TryRemoveOfKeyWithValueRetrievalDoesNotRemoveNonExistingItem

        public void TryRemoveOfKeyWithValueRetrievalDoesNotRemoveNonExistingItem()
        {
            // given
            var initialKvPs = new List<KeyValuePair<int, string>>()
            {
                new KeyValuePair<int, string>(1, "One")
            };

            using (var observableDictionary = new ObservableDictionary<int, string>(initialKvPs))
            {
                // when
                string value;
                var removalResult = observableDictionary.TryRemove(2, out value);

                // then check whether all items have been accounted for
                removalResult.Should().Be(false);
                value.Should().Be(default(string));

                observableDictionary.Count.Should().Be(1);
                observableDictionary.Should().Contain(1, "One");
            }
        }
开发者ID:jbattermann,项目名称:JB.Common,代码行数:22,代码来源:ObservableDictionaryModificationTests.cs

示例2: TryRemoveOfKeyThrowsOnNullKey

        public void TryRemoveOfKeyThrowsOnNullKey()
        {
            // given
            using (var observableDictionary = new ObservableDictionary<string, string>())
            {
                // when
                Action action = () => observableDictionary.TryRemove((string) null);

                // then
                action
                    .ShouldThrow<ArgumentNullException>()
                    .WithMessage("Value cannot be null.\r\nParameter name: key");

                observableDictionary.Count.Should().Be(0);
            }
        }
开发者ID:jbattermann,项目名称:JB.Common,代码行数:16,代码来源:ObservableDictionaryModificationTests.cs

示例3: TryRemoveOfKeyValuePairRemovesExistingItem

        public void TryRemoveOfKeyValuePairRemovesExistingItem()
        {
            // given
            var initialKvPs = new List<KeyValuePair<int, string>>()
            {
                new KeyValuePair<int, string>(1, "One")
            };

            using (var observableDictionary = new ObservableDictionary<int, string>(initialKvPs))
            {
                // when
                var removalResult = observableDictionary.TryRemove(1);

                // then check whether all items have been accounted for
                removalResult.Should().Be(true);
                observableDictionary.Count.Should().Be(0);
                observableDictionary.Should().NotContain(1, "One");
            }
        }
开发者ID:jbattermann,项目名称:JB.Common,代码行数:19,代码来源:ObservableDictionaryModificationTests.cs

示例4: TryRemoveOfKeyShouldNotThrowOnNonExistingItem

        public void TryRemoveOfKeyShouldNotThrowOnNonExistingItem()
        {
            // given
            using (var observableDictionary = new ObservableDictionary<int, string>())
            {
                // when
                Action invalidRemoveRangeForNonExistingKey = () => observableDictionary.TryRemove(10);

                // then

                invalidRemoveRangeForNonExistingKey
                    .ShouldNotThrow<ArgumentOutOfRangeException>();

                observableDictionary.Count.Should().Be(0);
            }
        }
开发者ID:jbattermann,项目名称:JB.Common,代码行数:16,代码来源:ObservableDictionaryModificationTests.cs


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