0

We know that internal keyword means access is limited to the current assembly. I'm from C background, so C just compiler each source file(.c) to assembly(.a) , so for .NET CLR, let's say we have two folders Model and Controller in an application, inside Model there are two class files(a.cs and b.cs), and inside Controller, there are also two class files (c.cs and d.cs). So when we compile the project, will a.cs and b.cs be compiled into same assembly file? or will all class files be compiled into same assembly file? Because from C's perspectives, it would be four assembly files (linker will produce only one executable file of course)

  • 3
    Welcome to Stack Overflow. It looks like you're (somewhat reasonably) assuming that the word "assembly" has a single meaning. "Assembly" in the .NET sense is *entirely different* to "assembly files" or "assembly language" that C would talk about. – Jon Skeet Mar 19 '19 at 07:36
  • .NET gives some manner of byte code, not assembler. – Lundin Mar 19 '19 at 07:54
  • Depends on your solution/project structure. Simply spoken an assembly is the resulting DLL or EXE file a project is compiled into. Thus if all your source is in just one project, you will only get one assembly. – ckuri Mar 19 '19 at 08:03

2 Answers2

0

At the end all the classes are going to be compiled into one Assembly for a project, but since you are talking about having same class name under different directory in that case also there will be only one assembly seperated logically by the namespace because classes under Model directory will be 'projectName.Model' and classes under controller directory will be 'projectName.Controller', but if you put these under same namespace, you are going to get a compilation issue because of duplicate class (to make it work you can make both the classes as partial class).

This link can help you as well

Hope this gives you a bit of idea...

piet.t
  • 11,718
  • 21
  • 43
  • 52
Abhinaw Kaushik
  • 607
  • 6
  • 18
  • 2
    Worth noting that Folder=Namespace is a guideline and a Visual Studio default but it is not enforced. You could make this not compiling. Folders have no meaning in C#. – H H Mar 19 '19 at 08:06
0

To simply answer your questions:

So when we compile the project, will a.cs and b.cs be compiled into same assembly file? or will all class files be compiled into same assembly file?

Yes, they will be compiled into same assembly file.

koviroli
  • 1,422
  • 1
  • 15
  • 27
  • But I remember I have an interface class(without access modifier, so it's "internal" by default) in the Model folder, so I did use `using nameSpace.Model;` in the class file d.cs in Controller folder, there was accessibility error, so I have to add "public" keyword in the interface. So if the default is internal, the class under Controller should be able to access the interface, since they all compiled into same assembly file, therefore access is OK to the current assembly according to the internal definition? –  Mar 19 '19 at 09:17
  • @slowjams In `C#` there is `class` and there is `interface` not both. In the first hand it worth nothing which folder your file in and which namespace they are but this is a recommendation by Microsoft. You can remember and you can think anything, the best thing you can do is to try that you doubt. Code it, compile it, run it and think about it. Btw. for these simple things you can use csc.exe(csharp compiler) and compile your files manually to see everything what happens without hightech IDEs eg. Visual Studio. – koviroli Mar 19 '19 at 12:00