The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 1,860 other subscribers

C# (and presumably Delphi): why parameterless record constructors are absent

Posted by jpluimers on 2019/09/12

For my link archive.

Full text at: [WayBack] … why the Delphi language does not allow parameterless constructors… – David Heffernan – Google+

Abstract:

+Stefan Glienke deleted his post about parameterless record constructors, presumably due to all the off topic comments.

.net at CLR level does allow parameterless constructors on structs. But the C# language bans them: https://msdn.microsoft.com/en-us/library/saxz13w4.aspx

Jon Skeet posted an answer on SO way back in 2008 on this topic: http://stackoverflow.com/a/333840/ From that answer:

—-
The CLR allows value types to have parameterless constructors, but C# doesn’t. I believe this is because it would introduce an expectation that the constructor would be called when it wouldn’t. For instance, consider this:

MyStruct[] foo = new MyStruct[1000];


—-

My guess is that Embarcadero decided to ban parameterless constructors on Delphi records for the same reason. Or perhaps they just copied the rules from C# without realising that the CLR supported parameterless struct constructors.

References:

--jeroen

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.