0

I downloaded a demo by Jon Skeet called 'PclPal' as found here - it refuses to compile in Visual Studio 2013 due to some C# syntax I don't recognise.

Two of the .cs files appear to have constructor logic in the actually class declarations, like so:

 public class Profile(string path, IEnumerable<SupportedRuntime> runtimes)
    {
        public string Name { get; } = System.IO.Path.GetFileName(path);
        public String Path { get; } = path;
        public IReadOnlyCollection<SupportedRuntime> SupportedRuntimes { get; } = runtimes.ToList().AsReadOnly();

What is this? Is this some future version of C# I've not yet learned?

EDIT: I don't see this as a duplicate question. The linked question says 'Why don't primary constructors compile?', whereas this question effectively says 'What are [these things that turn out to be] primary constructors?'

Community
  • 1
  • 1
Carlos P
  • 3,928
  • 2
  • 34
  • 50

1 Answers1

5

These are features that were originally coming to C# 6, "Auto Properties with Initializers" and "Primary Constructors".

https://msdn.microsoft.com/en-us/magazine/dn683793.aspx

Carlos P
  • 3,928
  • 2
  • 34
  • 50