scope of structure members

G

Guest

friends,
I have a question about accessing structure members.
I have a structure defined in my dll something like this.

namespace myNamespace
{
internal struct myStruct
{
int myMember1;
string myMember2;
}
}
Because I have declared the struct with scope internal, I
thought the scope of the members also would be internal,
but apparently not. So, I am having to explicitly declare
the structure members also as internal (in order to be
accessible from other .cs files in my assembly?) Is this a
good practice? If not, how do I get over the issue? Thanks
a lot for your help.
 
G

Guest

visibility on a type has nothing to do with it's members. and for any member without explicit visibility, it is assumed to be private by default. to make it visible outside of the struct, you need to either declare your fields as public or use public property to expose these fields. the latter is a better practice

----- (e-mail address removed) wrote: ----

friends
I have a question about accessing structure members
I have a structure defined in my dll something like this

namespace myNamespac

internal struct myStruc

int myMember1
string myMember2


Because I have declared the struct with scope internal, I
thought the scope of the members also would be internal,
but apparently not. So, I am having to explicitly declare
the structure members also as internal (in order to be
accessible from other .cs files in my assembly?) Is this a
good practice? If not, how do I get over the issue? Thanks
a lot for your help
 
J

Jon Skeet [C# MVP]

friends,
I have a question about accessing structure members.
I have a structure defined in my dll something like this.

namespace myNamespace
{
internal struct myStruct
{
int myMember1;
string myMember2;
}
}
Because I have declared the struct with scope internal, I
thought the scope of the members also would be internal,
but apparently not. So, I am having to explicitly declare
the structure members also as internal (in order to be
accessible from other .cs files in my assembly?) Is this a
good practice? If not, how do I get over the issue? Thanks
a lot for your help.

I never make non-constant fields visible - I always leave them with
their default visibility (private) and use properties to make them
accessible.

The accessibility of the class/structure has nothing to do with the
accessibility of the members of that class/structure, however: a public
class can (and usually will) have private members etc.
 

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