2010-06-21 Marek Habersack <mhabersack@novell.com>
[mcs.git] / class / Mono.C5 / UserGuideExamples / ThisFun.cs
blob9581a34e5e97275c3a26b4321ee597f37175c2d5
1 // Experiment: implicit conversion of indexer to function
2 // sestoft@dina.kvl.dk * 2005-11-08
4 using System;
5 using C5;
7 class MyFunTest {
8 public static void Main(String[] args) {
9 FooBar fb = new FooBar();
10 IList<int> list = new LinkedList<int>();
11 list.AddAll(new int[] { 2, 3, 5, 7, 11 });
12 list.Map<double>(fb).Apply(Console.WriteLine);
13 list.Apply(fb);
17 class FooBar {
18 public double this[int x] {
19 get {
20 Console.WriteLine(x);
21 return x + 1.5;
25 public Fun<int,double> Fun {
26 get {
27 return delegate(int x) { return this[x]; };
31 public Act<int> Act {
32 get {
33 return delegate(int x) { double junk = this[x]; };
37 public static implicit operator Fun<int,double>(FooBar fb) {
38 return delegate(int x) { return fb[x]; };
41 public static implicit operator Act<int>(FooBar fb) {
42 return delegate(int x) { double junk = fb[x]; };