473,412 Members | 4,957 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,412 software developers and data experts.

internal class, public members?


Can I simply mark a class as internal, or should I change all its public
members to internal as well?

If I can mark the class only as internal, it makes modifications easy.


Nov 15 '05 #1
5 7146
Andrew R. Thomas-Cramer <ar**@shell.core.com> wrote:
Can I simply mark a class as internal, or should I change all its public
members to internal as well?

If I can mark the class only as internal, it makes modifications easy.


You can certainly mark a class as internal, but that's different from
making its public members internal. For instance, suppose you have a
class which implements a public interface. Even though the class may be
internal, an instance may still "get out of the assembly" by being
returned from a member in another (public) class. That instance would
have to be referenced by the interface it implements rather than the
class name itself (as the class isn't known to the outside assembly)
but the public methods can still be called.

If the public methods aren't implementing any interfaces, I suspect it
would only make a difference in a very few reflection cases which you
may not care about.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too
Nov 15 '05 #2
lol, I considered mentioning nested classes, but thought this was a good
enough starting point. Should have mentioned those. Thanks.
"Jon Skeet" <sk***@pobox.com> wrote in message
news:MP************************@news.microsoft.com ...
Chris Taylor <ch*************@hotmail.com> wrote:
An internal class can have public members, internal is the default for
classes when no access modifier is specified.


... with the slight wrinkle that a type declared within another type
(example below) defaults to private.

public class Foo
{
class Nested // Defaults to private
{
}
}

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too

Nov 15 '05 #3
Jon Skeet <sk***@pobox.com> writes:
If the public methods aren't implementing any interfaces, I suspect it
would only make a difference in a very few reflection cases which you
may not care about.


In this case the assembly is being produced for a large corporation, may
be shared with partners, and will be distributed at thousands of sites
around the world. I'm curious what those reflection cases are. :)

Nov 15 '05 #4
Andrew R. Thomas-Cramer <ar**@shell.core.com> wrote:
Jon Skeet <sk***@pobox.com> writes:
If the public methods aren't implementing any interfaces, I suspect it
would only make a difference in a very few reflection cases which you
may not care about.


In this case the assembly is being produced for a large corporation, may
be shared with partners, and will be distributed at thousands of sites
around the world. I'm curious what those reflection cases are. :)


Fair enough. At this stage however I'm going into speculation...

I don't know exactly how the security over reflection works - but with
appropriately lax security settings, it's quite possible to interrogate
the internal types, and if an internal type has a public constructor,
you may even be able to instantiate it and call public methods on it
(again with reflection) where if those methods were internal, there
*may* be some situations where you could get the Type reference, but
not instantiate the type or call the methods.

Do you see what I mean, or do you want me to try to clarify that pretty
hideous sentence?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too
Nov 15 '05 #5
Jon Skeet <sk***@pobox.com> writes:
Do you see what I mean, or do you want me to try to clarify that pretty
hideous sentence?


I get it. Thanks!
Nov 15 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

19
by: Martin Oddman | last post by:
Hi, I have a compiling problem. Please take a look at the code below. I have an application that is built upon three tiers: one data tier (Foo.DataManager), one business tier (Foo.Kernel) and...
2
by: Chien Lau | last post by:
I frequently define internal UserControl-derived classes in my WinForms apps: internal class MyUserControl:UserControl{ ... } I'll often need to embed these controls in a Form, whose class...
6
by: Sgt. Sausage | last post by:
I know it's not possible, but I need a protected internal interface: protected internal interface ISomeInterface{ // yadda yadda yadda } Basically, I need an interface that is completely...
12
by: Anders Borum | last post by:
Hello! I was wondering why we're allowed to define interfaces as internal, when all the members of the interface, when implemented in a class, are made public? I know that interfaces serve as...
5
by: TEK | last post by:
When using reflection, the Type.GetProperty method has the following signature: Type.GetProperty(String, BindingFlags) The doc says: a.. Specify BindingFlags.Public to include public properties...
6
by: Plamen Doykov | last post by:
Hi all I have converted a simple project from ASP.NET 1 to 2.0 with the latest prerelease of Visual Studio 2005. The problem is I can't access internal members from the code behind. It gives:...
4
by: newbie120 | last post by:
Hi all maybe its just been a long day, but i have a question about call access modifiers in C#. Consider the following code. namespace Application { private class Class1 { int i;
9
by: JT | last post by:
Here is the overall structure I will be referring to: End-program ProvideWorkFlow.dll Forms and methods that properly manipulate calls to methods in AccessUtils AccessUtils (a web service)...
4
by: ~~~ .NET Ed ~~~ | last post by:
I am facing a problem. My project is composed of several assemblies. In one of them -the backend- I have several internal classes that must implement an interface. These internal classes are only...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.