与C#中的typedef等效

本文翻译自:Equivalent of typedef in C#

Is there a typedef equivalent in C#, or someway to get some sort of similar behaviour? 在C#中是否存在与typedef等价的东西,或者以某种方式获得了类似的行为? I've done some googling, but everywhere I look seems to be negative. 我已经进行了一些谷歌搜索,但是到处看起来都是负面的。 Currently I have a situation similar to the following: 目前,我的情况类似于以下情况:

class GenericClass<T> 
{
    public event EventHandler<EventData> MyEvent;
    public class EventData : EventArgs { /* snip */ }
    // ... snip
}

Now, it doesn't take a rocket scientist to figure out that this can very quickly lead to a lot of typing (apologies for the horrible pun) when trying to implement a handler for that event. 现在,不需要火箭科学家去弄清楚,当尝试为该事件实现处理程序时,这会很快导致很多类型的输入(对可怕的双关语表示歉意)。 It'd end up being something like this: 最终会变成这样:

GenericClass<int> gcInt = new GenericClass<int>;
gcInt.MyEvent += new EventHandler<GenericClass<int>.EventData>(gcInt_MyEvent);
// ...

private void gcInt_MyEvent(object sender, GenericClass<int>.EventData e)
{
    throw new NotImp
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值