我研究了Y Combinator(使用c#5.0)并且在这种方法时非常惊讶:
public static Func<T1, Func<T2, TOut>> Curry<T1, T2, TOut> ( this Func<T1, T2, TOut> f)
{
return a => b => f(a, b);
}
Run Code Online (Sandbox Code Playgroud)
...由编译器翻译成:
public static Func<T1, Func<T2, TOut>> Curry<T1, T2, TOut>(this Func<T1, T2, TOut> f)
{
first<T1, T2, TOut> local = new first<T1, T2, TOut>();
local.function = f;
return new Func<T1, Func<T2, TOut>>(local.Curry);
}
private sealed class first<T1, T2, TOut>
{
private sealed class second
{
public first<T1, T2, TOut> ancestor;
public T1 firstParameter;
public TOut Curry(T2 …Run Code Online (Sandbox Code Playgroud) 最近我写了一些树,想尝试不安全的代码.最后我做的都没有不安全但是在这段代码中找到了一些模糊(对我而言)的地方(对于更短的代码,我删除所有逻辑,所以所有代码看起来都毫无意义):
public static void Main() {
EqClass a = new EqClass();
a.AddElement(2, new record(3)); // *place1*
...
}
unsafe struct node {
public node* next;
public record Value;
public node(record value) {
this = new node();
this.Value = value;
}
}
struct record {
public int a;
public record(int a) {
this.a = a;
}
}
unsafe class EqClass {
node*[] last = new node*[3];
public void AddElement(int classIndex, record element) {
node a = new node(element);
node* newNode = …Run Code Online (Sandbox Code Playgroud)