6

In C# I can have references of methods and static methods. Can I also get the reference of a classes constructor?

In Java I can say Supplier<MyClass> createMyClass = MyClass::new (instead of the longer lambda syntax).
In C# I only know the notation Func<MyClass> createMyClass = () => MyClass(). But I think the Java way with the constructor reference is better readable.

And I don't want to make a static CreateMyClass function. I really want the constructor.

Amal K
  • 4,359
  • 2
  • 22
  • 44
danielspaniol
  • 2,228
  • 21
  • 38

1 Answers1

10

No, there's no equivalent of method group conversions for constructors, or properties, indexers or operators.

It's an entirely reasonable idea, but it isn't in C# at the moment. It is, however, tracked as part of a feature request in the C# design repo - so you may want to subscribe to that issue.

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194