小编hol*_*roy的帖子

对于Action <>和/或Func <>,c#中的typedef等价

谷歌搜索后看起来并不乐观,但我想知道在使用Action<T>Func<in T, out TResult>在C#中是否有某种混叠或类型定义的方法?

我已经在c#中看到了typedef的等价,它说在一个编译范围内你可以在using某些情况下使用该构造,但就我所知,这似乎并不适用于Action's和Funcs.

我想要这样做的原因是我想要一个动作用作多个函数的参数,如果我在某个时间点决定改变动作,那么很多地方都要改变它们作为参数类型和作为变量类型.

?typedef? MyAction  Action<int, int>;

public static SomeFunc(WindowClass window, int number, MyAction callbackAction) {
   ...
   SomeOtherFunc(callbackAction);
   ...
}

// In another file/class/...
private MyAction theCallback;

public static SomeOtherFunc(MyAction callbackAction) {
    theCallback = callbackAction;
}
Run Code Online (Sandbox Code Playgroud)

是否有一些构造要使用,它可以定义MyAction代码段中指示的?

c# delegates types

7
推荐指数
2
解决办法
3144
查看次数

在python中初始化或附加字典列表

以下代码片段可以以某种方式简化为一个语句吗?

if aKey not in aDict:
    aDict[aKey] = [someValue]
else: 
    aDict[aKey].append(someValue)
Run Code Online (Sandbox Code Playgroud)

我可以写一个函数接受aDict,aKeysomeValue,但有没有办法做到这一点只使用原生的Python的东西?

python dictionary initialization list

0
推荐指数
1
解决办法
83
查看次数

标签 统计

c# ×1

delegates ×1

dictionary ×1

initialization ×1

list ×1

python ×1

types ×1