Skip to content

Instantly share code, notes, and snippets.

@nanwang2016
Created August 1, 2020 16:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nanwang2016/715f2b0ff6617b37ebc93ba9c5cf2776 to your computer and use it in GitHub Desktop.
Save nanwang2016/715f2b0ff6617b37ebc93ba9c5cf2776 to your computer and use it in GitHub Desktop.
namespace TestFile
{
class Program
{
static void Main(string[] args)
{
//Only Defaul Constructor with parameters is valid, as Private Constructor is not allowed to create an instance.
Student UniStudent = new Student("Jack", "007");
}
}
public class Student
{
//Private Constructor
private Student()
{
Console.WriteLine("I am a Private Constructor");
}
public static string name, studentID;
//Default Constructor with parameters
public Student(string a, string b)
{
name = a;
studentID = b;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment