I've created a struct named Point
and a List
of such points:
var myPoints = new List<Point> {
new Point() {Col = 3, Row = 2},
new Point() {Col = 2, Row = 4},
new Point() {Col = 5, Row = 4},
};
When I try to print them using ForEach()
method, I cannot pass a method group there: myPoints.ForEach(Console.WriteLine);
gives a compile time error saying that a method with void WriteLine(Point)
signagure is expected. If I use a lambda expression or change Point
to be a class instead of struct it works just perfectly.
Why does it happen even though there's always an implicit conversion from any value type to object
via boxing -- and the method Console.WriteLine(object)
should therefore be chosen?
Thank you!