I'm trying to use lambda expression in C#:
using System;
namespace ConsoleApplication1 {
public struct Point {
public int x;
public int y;
public Point( int x, int y ) {
this.x = x;
this.y = y;
}
}
public interface Mobile {
Point getPosition();
}
public class Program {
public void mth( Mobile mobile ) {
Point p = mobile.getPosition();
Console.WriteLine( "{ " + p.x + ", " + p.y + " }" );
}
static void Main( string[] args ) {
new Program().mth( () => { return new Point( 4, 5 ); } ); <<<<<<<< ERROR
}
}
}
Compiler error (in French):
Impossible de convertir expression lambda en type 'ConsoleApplication1.Mobile', car il ne s'agit pas d'un type délégué
International English Translation:
Unable to convert lambda expression to type 'ConsoleApplication1.Mobile', because isn't a delegate type
What's the right syntax?
getPosition()fromMobilebut you are trying to create one using an anonymous function that returns aPoint... can you explain what you are trying to do?