Welcome to mirror list, hosted at ThFree Co, Russian Federation.

ThisFun.cs « UserGuideExamples « Mono.C5 « class « mcs - github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 1fd29f1c1223e8dbd2c9de2ad10b196bfacac6c4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// Experiment: implicit conversion of indexer to function
// sestoft@dina.kvl.dk * 2005-11-08

using System;
using C5;

class MyFunTest {
  public static void Main(String[] args) {
    FooBar fb = new FooBar();
    IList<int> list = new LinkedList<int>();
    list.AddAll(new int[] { 2, 3, 5, 7, 11 });
    list.Map<double>(fb).Apply(Console.WriteLine);
    list.Apply(fb);
  }
}

class FooBar {
  public double this[int x] { 
    get { 
      Console.WriteLine(x); 
      return x + 1.5; 
    } 
  }

  public Fun<int,double> Fun {
    get { 
      return delegate(int x) { return this[x]; };
    }
  }

  public Act<int> Act {
    get { 
      return delegate(int x) { double junk = this[x]; };
    }
  }
  
  public static implicit operator Fun<int,double>(FooBar fb) {
    return delegate(int x) { return fb[x]; };
  }  

  public static implicit operator Act<int>(FooBar fb) {
    return delegate(int x) { double junk = fb[x]; };
  }  
}