© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•2y ago•
11 replies
steven preadly

When should i use Private constractor with factory method?

here included example
public class Student
{

    private string name;
    private Student(string  name) 
    {
        this.name = name;
    }

    public static Student CreateObject(string name) 
    {
        return new Student(name);
    }

    public string Name 
    {
        get { return name; }
    }


}
public class Student
{

    private string name;
    private Student(string  name) 
    {
        this.name = name;
    }

    public static Student CreateObject(string name) 
    {
        return new Student(name);
    }

    public string Name 
    {
        get { return name; }
    }


}
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

✅ Factory method
C#CC# / help
16mo ago
✅ Factory Method Pattern
C#CC# / help
17mo ago
✅ Confused when try to implement Factory Method
C#CC# / help
2y ago
Design Patterns / Factory Method
C#CC# / help
17mo ago