469,299 Members | 2,069 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,299 developers. It's quick & easy.

what is the default access modifier in the class if not specified

/*1 not specified*/class {

/*2 not specified*/ void Foo(){}

}

Will they, like in c++, default to private?

Thanks
Sep 24 '08 #1
8 3932
Methods are private as are properties and variables.
Classes are internal

--
Ciaran O''Donnell
http://wannabedeveloper.spaces.live.com
"puzzlecracker" wrote:
/*1 not specified*/class {

/*2 not specified*/ void Foo(){}

}

Will they, like in c++, default to private?

Thanks
Sep 24 '08 #2
puzzlecracker <ir*********@gmail.comwrote:
/*1 not specified*/class {

/*2 not specified*/ void Foo(){}

}

Will they, like in c++, default to private?
The default accessibility is always the most private possible. So for
top-level (non-nested) types, the default access is internal. For
nested types, it's private. For methods, fields, properties, events,
constructors and constants, it's always private.

There's *one* exception to this rule, which is property access. If you
have a property like this:

public int Foo
{
get { ... };
set { ... };
}

you could make either part of it private like this:

public int Foo
{
get { ... };
private set { ... };
}

That's the only place (that I'm aware of) in C# where explicitly
specifying an access level gives you a more restricted level than the
default. (Here the default access for each part of the property is
whatever access the overall property is specified as.)

--
Jon Skeet - <sk***@pobox.com>
Web site: http://www.pobox.com/~skeet
Blog: http://www.msmvps.com/jon.skeet
C# in Depth: http://csharpindepth.com
Sep 24 '08 #3
On Sep 24, 7:55*am, puzzlecracker <ironsel2...@gmail.comwrote:
/*1 not specified*/class {

* */*2 not specified*/ void Foo(){}

}

Will they, like in c++, default to private?

Thanks
Puzzle,

internal for top level classes and private for nested classes.

-Jay
Sep 24 '08 #4
On Sep 24, 10:55 am, puzzlecracker <ironsel2...@gmail.comwrote:
/*1 not specified*/class {

/*2 not specified*/ void Foo(){}

}

Will they, like in c++, default to private?

Thanks
internal
member's (properties, attributes & methods) are private by defualt
Sep 24 '08 #5
On Sep 24, 11:07*am, Ciaran O''Donnell
<CiaranODonn...@discussions.microsoft.comwrote:
Methods are private as are properties and variables.
Classes are internal

--
Ciaran O''Donnellhttp://wannabedeveloper.spaces.live.com

"puzzlecracker" wrote:
/*1 not specified*/class {
* */*2 not specified*/ void Foo(){}
}
Will they, like in c++, default to private?
Thanks
internal?
Sep 24 '08 #6
internal?

Access limited to other types in the same assembly.

Marc
Sep 24 '08 #7
On Sep 24, 4:49 pm, Marc Gravell <marc.grav...@gmail.comwrote:
internal?

Access limited to other types in the same assembly.

Marc
by assembly you mean package/namespace?
Sep 25 '08 #8
by assembly you mean package/namespace?

The two are different concepts. If, by "package", you mean the dll/
exe, then yes: but the correct term in .NET is assembly.

A namespace is purely a notational device to help you (the developer)
organise code; it has no specific affect on access, and is orthogonal
to the assembly concept: an assembly can contribute multiple
namespaces, and multiple assemblies can contribute to the same
namespace.

Marc
Sep 25 '08 #9

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Dan Disney | last post: by
1 post views Thread by Jacob N. Rohde | last post: by
3 posts views Thread by fh1996 | last post: by
9 posts views Thread by Vladimir Bezugliy | last post: by
8 posts views Thread by Stanislav Simicek | last post: by
4 posts views Thread by Gery D. Dorazio | last post: by
3 posts views Thread by Mr Newbie | last post: by
11 posts views Thread by prefersgolfing | last post: by
6 posts views Thread by Tony Johansson | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by harlem98 | last post: by
1 post views Thread by Geralt96 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.