动作属性 [英] Action properties

查看:124
本文介绍了动作属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以向我解释此代码摘录吗。

Can anybody explain me this code extract.

public abstract Action<int> serialpacket { set; get; }

我对此有些困惑。我大致知道它的作用,但是如果有人可以对此有所了解会更好。

I am a bit confused about it. I know roughly what it does but it would be better if somebody can shed a bit light on it.

推荐答案

serialpacket 是一个抽象属性,实现后将返回带有整数参数且不返回任何内容的方法引用或lamda。

serialpacket is an abstract property that, when implemented, will return a method reference or lamda that takes an integer parameter and returns nothing.

public override Action<int> serialpacket
{
    get { return i => Console.WriteLine(i); }
    set { ... }
}

public void Trousers(int i)
{
   Console.WriteLine(i);
}

public Action<int> serialpacket
{
    get { return Trousers; }
    set { ... }
}

然后可以使用serialpacket因此:

One could then use serialpacket thusly:

serialpacket(10);

由于它是带有二传手的财产,因此也可以:

As it is a property with a setter, one could also do:

public override Action<int> serialpacket { get; set; }

serialpacket = Trousers;
serialpacket(10);
// prints 10 to the console

具有与裤子如上。

这篇关于动作属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆