C#C
C#11mo ago
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:

C#

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
Was this page helpful?