© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•13mo ago•
27 replies
Faker

✅ Public class in C#

Hello guys, sorry to disturb you all; can someone explain when do we use a "public class" and non-public class in C# pls. For example, consider the following code:

using System;

namespace Learning
{
    class Program
    {
        static void Main(string[] args)
        {
            . . .
        }

        
    }
}
using System;

namespace Learning
{
    class Program
    {
        static void Main(string[] args)
        {
            . . .
        }

        
    }
}


I didn't use TLS. I use write "class"; does it have a default value? like private class / public class? if so, what do these values represent pls. When should we use private/ public or just write class and why?

Say when we create new classes, like a class for person etc, it matters if we put private/public or anything? Also, if a class is public, it can only have one public class within the same file ?

Now, consider the code above, can I create multiple classes within that same file? Like when after the class Program ending curly braces, I juste write a class, named "class Person" ? Is that good practice/recommended?

Sorry that's a lot of questions
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

❔ ✅ public class
C#CC# / help
4y ago
class constructor in c#
C#CC# / help
12mo ago
c# class
C#CC# / help
3y ago
✅ Parse .md like .json in C# class
C#CC# / help
3y ago