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

The internal key word does not work as a book say.

Hello!

I want to say that I rather new to C# have only worked with it for 5 month.

I'm now reading a book and there are some example on the internal key work
that doesn't work
as the book say. I just want to know if the book is right or wrong.

I have two files with two classes called Class1 and Class2.
The first Class Class1 is located in namespace AccessControl and the second
class
Class2 is located in namespace Test. You can see the classes below.
Class2 has the internal key word on both the class and the constructor and
on the method A_internal().
I can instansiate Class2 from Class1 without any problem and also call the
A_internal() metod that exist in Class2 from Class1 without any problem.

Can somebody explain how this internal work?
//Here is file 1 with name Class1.cs
using System;
using Test;

namespace AccessControl
{
public class Class1
{
public Class1() {} //constructor
public static int Main(string[] strings)
{
Class2 ba = new Class2();
return 0;
}
}
}

//Here is file 2 with name class2.cs
using System;
namespace Test
{
internal class Class2
{
internal Class2() {} //Constructor

internal void A_internal()
{
Console.WriteLine("Class2.A_internal");
}
}
}

Many thanks

//Tony


Apr 15 '06 #1
3 1701
that's possible if Class1 and Class2 are in the same assembly.

Apr 15 '06 #2
Tony Johansson <jo*****************@telia.com> wrote:
I want to say that I rather new to C# have only worked with it for 5 month.

I'm now reading a book and there are some example on the internal key work
that doesn't work
as the book say. I just want to know if the book is right or wrong.

I have two files with two classes called Class1 and Class2.
The first Class Class1 is located in namespace AccessControl and the second
class
Class2 is located in namespace Test. You can see the classes below.


Does your book definitely say that "internal" is to do with namespaces?
It's not - it's to do with assemblies. Two types which are in different
assemblies can't see each others' internal members. (And a type can't
see internal types in a different assembly.)

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Apr 15 '06 #3
Tony Johansson wrote:
Hello!

I want to say that I rather new to C# have only worked with it for 5
month.
I'm now reading a book and there are some example on the internal key work
that doesn't work
as the book say. I just want to know if the book is right or wrong.


Classes and methods marked as internal are available to other classes and
methods in the same assembly. Namespace is irrelevant in this context. You
can have multiple namespaces in the same assembly, and the same namespace in
mulitple assemblies. But the internal modifier means that anything marked
as such is accessible within the same assembly, but inaccessible outside the
assembly.

Re-read that section of the book and see if it isn't saying that internal
scopes an item to the assembly, rather than to the namespace.
--
Tom Porterfield

Apr 15 '06 #4

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

Similar topics

4
by: Mickel Grönroos | last post by:
Hi! I'm fiddling with Python for Windows (normally using Linux) and as a part of that I want to try to make a simple word frequency list generator to be used in conjunction with Microsoft Word....
5
by: K. Shier | last post by:
when attempting to edit code in a class file, i see the bug "Visual Basic ..NET compiler is unable to recover from the following error: System Error &Hc0000005&(Visual Basic internal compiler...
5
by: Michiel Kamermans | last post by:
Hi, I've been trying to find a free docbook to word converter, because final visual styling of my book is a lot easier in a wysiwyg editor than by writing a lot of XSLT, but seem to only run...
4
by: astro | last post by:
I've been looking at the event sinking example in Litwin et. al. "Access 97 Developer's Handbook" and I am able to event sink the 2 events listed - those being the "_quit" and "_documentchange"...
4
by: Dadio | last post by:
Hello On my Access database form I have a command button which opens a Word mail merge document in which I have created a number of fields (Title, FirstName, LastName, Address1 etc.) I would...
5
by: Mason | last post by:
I'm having some problems converting VBA for Word 2000 to code that VB.Net understands. I recorded a macro in Word to add numbering (a. b. c.) to my paragraphs. I managed to translate quite a bit...
4
by: stocki | last post by:
Hi Everybody, one of my C# apps copies charts from an Excel workbook into a table in a word document. ((Excel.ChartObject) myGraphicsWorksheet.ChartObjects(1)).Copy(); myvalue =...
6
by: Simon | last post by:
on my frmCustomer form i would like a button that open up words and runs a mail merger only with the data on on that form ( as on the mail merger i just want the customer address for when i write a...
8
by: Bllich | last post by:
hello, I have winForm app and I have some text and pictures that I want to save into a word file when I read it from a database. I don't know how many text or pictures do I have for one value in...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.