Difference between "class" and "public class"

M

Matt

Hi everyone,

can someone point out the difference between defining a class with the
public access modifier and just leaving it as it is (default in vs.net
"class")

I think that the default access modifier applied if one isn't defined;
so class would in fact be read as "private class" when it's compiled,
but that isn't the case.

When the code below code compiles, it will throw an error for c3, but
not for the other two classes. The fact that they're in different
namespaces also rules out that "class" is only visible within a
namespace.

I thought it might be only assembly-wide visible if defined without
the public access modifier, but, uh, I guess that's what the internal
keyword is for.

Thanks,
Matt

namespace ConsoleApplication
{
class Program
{
static void Main(string[] args)
{
var c1 = new n1.c1();
var c2 = new n2.c2();
var c3 = new n3.c3();
}
}
}

namespace n1
{
class c1
{
}
}

namespace n2
{
class c2
{
}
}

namespace n3
{
private class c3
{
}
}
 
M

Marc Gravell

"private class" makes no sense at the namespaec level; the default
access modifier is "internal".

So "class" (at the namespace level) is "internal class".

Marc
 
M

Matt

"private class" makes no sense at the namespaec level; the default
access modifier is "internal".

So "class" (at the namespace level) is "internal class".

Marc

Ah, Cheers!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top