小编chi*_*kak的帖子

.NET的简单事件总线

我想创建一个非常简单的事件总线,它允许任何客户端订阅特定类型的事件,当任何发布者使用EventBus.PushEvent()方法在总线上推送事件时,只有订阅该特定事件类型的客户端才能获得该事件.

我正在使用C#和.NET 2.0.

.net generics events bus c#-2.0

15
推荐指数
3
解决办法
3万
查看次数

在Dictionary <Key,Collection <Value >>中自动创建集合

很多时候我要创造一个 Dictionary<KeyType, List<ValueType>>

在我开始使用字典之前,我必须首先验证是否已为该密钥创建了List.

//Can i remove these two lines?
if(!dict.ContainsKey(key)) 
    dict[key]= new List<ValueType>;

//now use the key
dict[key].Add(value);
Run Code Online (Sandbox Code Playgroud)

我知道它只有"2行"的代码,但它让我烦恼,我认为它可以删除.

我可以在某种程度上扩展字典但在我做之前,我想知道是否有人找到了一种聪明的方法来删除上述if语句.

基本上我想创建一个Dictionary<KeyType, Collection<ValueType>>并立即开始使用它dict[key].Add(value).

.net c# collections dictionary

7
推荐指数
1
解决办法
2537
查看次数

为什么Decimal.MaxValue - 0.5的结果是整数?

我今天正在玩小数.我注意到了这个:

Decimal.MaxValue 
79228162514264337593543950335

Decimal.MaxValue - 0.5m
79228162514264337593543950334
Run Code Online (Sandbox Code Playgroud)

以下代码打印为true.

static void Main(string[] args)
        {
            decimal d = Decimal.MaxValue - 0.5M;
            var b = d % 1 == 0;
            Console.WriteLine(b);

        }
Run Code Online (Sandbox Code Playgroud)

我确信这背后有一个原因,但我不知道它是什么.

.net c# decimal

5
推荐指数
1
解决办法
4611
查看次数

标签 统计

.net ×3

c# ×2

bus ×1

c#-2.0 ×1

collections ×1

decimal ×1

dictionary ×1

events ×1

generics ×1