c# - 用&符号分隔的和弦C#方法?

标签 c# polyphonic-c#

我正在阅读 this introduction to Polyphonic C#第一页包含此示例:

Example: A Simple Buffer

Here is the simplest interesting example of a Polyphonic C# class:

public class Buffer {
    public String get() & public async put(String s) {
        return s;    
    } 
}

我完全不明白。
方法 get()put() 之间的 & 表示什么?

最佳答案

这不是合法的 C#。那是和弦 C#。那是一个 research project from Microsoft .遗憾的是它没有精确定义1 但重点是:

In Polyphonic C#, however, a body may be associated with a set of (synchronous and/or asynchronous) methods. We call such a definition a chord, and a particular method may appear in the header of several chords. The body of a chord can only execute once all the methods in its header have been called.

因此,& 将这些方法“绑定(bind)”到一个 chord 中,直到调用 chord 中的所有方法时才会调用该 chord。

再往前走一点 article :

These two methods appear (separated by an ampersand) in the header of a single chord, the body of which consists of the return statement. Now assume that b is an instance of Buffer and that producer and consumer threads wish to communicate via b. Producers make calls to put(), which, since the method is asynchronous, do not block. Consumers make calls to get(), which, since the method is synchronous, will block until or unless there is a matching call to put(). Once b has received both a put() and a get(), the body runs and the argument to the put() is returned as the result of the call to get(). Multiple calls to get() may be pending before a put() is received to reawaken one of them and multiple calls to put() may be made before their arguments are consumed by subsequent get()s.

1:但是,这就是前沿的本质。我明白了。

关于c# - 用&符号分隔的和弦C#方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17557459/

相关文章:

c# - 从 OnActionExecuting 访问方法的属性

c# - 无法计算出 XPath 计数表达式结果。 C# xml Web 服务

c# - 将 XmlSerializer 与根元素中的数组一起使用

c# - WinForm 在运行时更改大小...高 DPI 相关?

c# - 如何使用 Jering.Javascript.NodeJS 通过 .net core 和 nodejs 运行 Typescript ES6+ 服务器端