Skip to content

Instantly share code, notes, and snippets.

@svick
Created August 22, 2014 22:48
Show Gist options
  • Save svick/5e60c304ee73598f93f3 to your computer and use it in GitHub Desktop.
Save svick/5e60c304ee73598f93f3 to your computer and use it in GitHub Desktop.
C# 6.0 primary constructor accessibility
class Program
{
static void Main()
{
new PublicConstructor(""); // OK
new PrivateConstructor(""); // error CS0122: 'Program.PrivateConstructor.PrivateConstructor(string)' is inaccessible due to its protection level
new PrimaryConstructor(""); // OK
}
private class PrimaryConstructor(string firstName)
{
}
private class PublicConstructor
{
public PublicConstructor(string firstName)
{
}
}
private class PrivateConstructor
{
private PrivateConstructor(string firstName)
{
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment