473,396 Members | 2,002 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,396 software developers and data experts.

Scope of internal method in C#?

I've seen lots of mentions of the scope of an "internal" class.

What's the scope of an "internal" method. Why would one use it as
opposed to an "internal" class?

Thanks in advance.

Adam

Nov 17 '05 #1
8 32688
You would not use one as opposed to the other.
If you have a class that you want exposed outside of your project, then it's
public (or protected). You may have some methods in that class that are only
accessed from your project - these would be Internal methods. If you have a
class where none of the methods or fields are to be exposed outside of the
project, then the class should be Internal.

If the class-level access is more restrictive than the member-level access,
then the more restrictive access applies.

David Anton
www.tangiblesoftwaresolutions.com
Home of the Instant C# VB.NET to C# converter
and the Instant VB C# to VB.NET converter

"Adam" wrote:
I've seen lots of mentions of the scope of an "internal" class.

What's the scope of an "internal" method. Why would one use it as
opposed to an "internal" class?

Thanks in advance.

Adam

Nov 17 '05 #2
In message <11**********************@o13g2000cwo.googlegroups .com>, Adam
<ad*********@hotmail.com> writes
I've seen lots of mentions of the scope of an "internal" class.

What's the scope of an "internal" method. Why would one use it as
opposed to an "internal" class?

Thanks in advance.


You may want a method on a public class which can be called by other
classes in the assembly, but not by clients of the assembly. Imagine you
have a container class managing a collection of Things. A Thing knows
how to delete its database record, but you want to ensure that when a
Thing is deleted, it is also removed from the collection:

public class ThingCollection
{
private Hashtable things;
public void DeleteThing(Thing toDelete)
{
toDelete.Delete();
this.things.Remove(toDelete.ID);
}
}
public class Thing
{
internal void Delete()
{
//Delete from database
}
}

--
Steve Walker
Nov 17 '05 #3
A class with internal access is visible to all other classes within the same
assembly. A method with internal access can be considered as if it were
public within the same assembly and private elsewhere.

This enables you to create classes which only expose a limited number of
their total methods to consumers of the assembly while enabling your own
code within the assembly priveliged assess to certain methods.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.

"Adam" <ad*********@hotmail.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
I've seen lots of mentions of the scope of an "internal" class.

What's the scope of an "internal" method. Why would one use it as
opposed to an "internal" class?

Thanks in advance.

Adam

Nov 17 '05 #4
I wish internal worked as described, but it seems to only work when it is
within one file. This seems rather strange, as there is no abstaction level
of "file" in C# that the programmer observes (yes I know the blob behind
knows files).
Personally I think internal should abstract to the name space, something
that actually exists to the programmer. This would also simplify export of
dll files.

"Bob Powell [MVP]" wrote:
A class with internal access is visible to all other classes within the same
assembly. A method with internal access can be considered as if it were
public within the same assembly and private elsewhere.

This enables you to create classes which only expose a limited number of
their total methods to consumers of the assembly while enabling your own
code within the assembly priveliged assess to certain methods.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.

"Adam" <ad*********@hotmail.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
I've seen lots of mentions of the scope of an "internal" class.

What's the scope of an "internal" method. Why would one use it as
opposed to an "internal" class?

Thanks in advance.

Adam


Nov 17 '05 #5
GRiN <GR**@discussions.microsoft.com> wrote:
I wish internal worked as described, but it seems to only work when it is
within one file.
No, that's not true. If you're running into it as a problem, could you
post a short but complete program which demonstrates it?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.

This seems rather strange, as there is no abstaction level
of "file" in C# that the programmer observes (yes I know the blob behind
knows files).
Personally I think internal should abstract to the name space, something
that actually exists to the programmer. This would also simplify export of
dll files.


It would be useful to have a namespace access modifier, but internal is
useful too. It's a pain with .NET having one and Java having the other
- it would be so nice to have one environment with both...

(The idea of an assembly definitely exists to the programmer, IMO.)

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 17 '05 #6
GRiN <GR**@discussions.microsoft.com> wrote:
I wish internal worked as described, but it seems to only work when it is
within one file.
No, that's not true. If you're running into it as a problem, could you
post a short but complete program which demonstrates it?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.

This seems rather strange, as there is no abstaction level
of "file" in C# that the programmer observes (yes I know the blob behind
knows files).
Personally I think internal should abstract to the name space, something
that actually exists to the programmer. This would also simplify export of
dll files.


It would be useful to have a namespace access modifier, but internal is
useful too. It's a pain with .NET having one and Java having the other
- it would be so nice to have one environment with both...

(The idea of an assembly definitely exists to the programmer, IMO.)

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 17 '05 #7
So I went to collect the screens and found something very interesting.
First I am using VS2003.NET on W2k.
First I take a class and change it from public to internal.
I then change the instanuation to internal for proper scope.
Then I do a "Build".
Errors spring up for every use of the class about protection levels.
I then change ANY of the called routines from public to internal.
Then I do a "Build".
No errors!
I then switch the called routine back to public .
Then I do a "Build".
No errors!
It seems to work from then on...
Think the partial build command misses the change?
(I haven't tried ReBuild on the first change)
"Jon Skeet [C# MVP]" wrote:
GRiN <GR**@discussions.microsoft.com> wrote:
I wish internal worked as described, but it seems to only work when it is
within one file.


No, that's not true. If you're running into it as a problem, could you
post a short but complete program which demonstrates it?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.

This seems rather strange, as there is no abstaction level
of "file" in C# that the programmer observes (yes I know the blob behind
knows files).
Personally I think internal should abstract to the name space, something
that actually exists to the programmer. This would also simplify export of
dll files.


It would be useful to have a namespace access modifier, but internal is
useful too. It's a pain with .NET having one and Java having the other
- it would be so nice to have one environment with both...

(The idea of an assembly definitely exists to the programmer, IMO.)

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

Nov 17 '05 #8
GRiN <GR**@discussions.microsoft.com> wrote:
So I went to collect the screens and found something very interesting.
First I am using VS2003.NET on W2k.
First I take a class and change it from public to internal.
I then change the instanuation to internal for proper scope.
Then I do a "Build".
Errors spring up for every use of the class about protection levels.
I then change ANY of the called routines from public to internal.
Then I do a "Build".
No errors!
I then switch the called routine back to public .
Then I do a "Build".
No errors!
It seems to work from then on...
Think the partial build command misses the change?
(I haven't tried ReBuild on the first change)


It's possible. I've seen VS.NET get its knickers in a twist like that
before, occasionally. A rebuild usually sorts things out.

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

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

Similar topics

6
by: Hal Vaughan | last post by:
Being self taught, this is one thing I've always had trouble with -- I finally get it straight in one situation and I find I'm not sure about another. I have a class that keeps calling an...
8
by: TTroy | last post by:
I have a few questions about "scope" and "visibility," which seem like two different things. To me "visibility" of the name of a function or object is the actual code that can use it in an...
7
by: Kobu | last post by:
The code below isn't compiling for me (error message: conflicting types for 'total' - pointing to the extern declaration). Why wouldn't this work, since the types are different, the extern...
8
by: Carlos J. Quintero | last post by:
Hi, As you know the current keywords "protected internal" (C#) or "Protected Friend" (VB.Net) means "Protected Or internal" (C#) or "Protected Or Friend" (VB.Net), that is, the member is...
1
by: tolisss | last post by:
Hi there is a method at an external assembly that i want to invoke with signature internal void RaiseKeyUp(KeyEventArgs e) and i m trying like ...
3
by: ssg31415926 | last post by:
I have an abstract base class from which has concrete subclasses. I have a method on the base class marked as 'protected internal'. I have another class in the same assembly which holds a...
1
by: dcreedon | last post by:
Hello, I have 3 files a.java b,java (a class with comms functions) and c.java (the program GUI) in different packages. object a and object b are created in a.java. I want to get input...
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)...
3
by: Paul McGuire | last post by:
Is there any way to hide portions of an exception stack trace? When users get exceptions when using pyparsing, there are usually many layers of pyparsing-internal stack messages that are not at...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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,...

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.