Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt

Use this file to discover all available pages before exploring further.

An internal method in C# is a method declared with the internal access modifier, restricting its visibility and accessibility strictly to the current assembly (the compiled .exe or .dll) in which it is defined. Any code within the same assembly can invoke the method, but it remains inaccessible to code in external assemblies referencing the library.
public class ComputationEngine
{
    // Accessible by any class within the same compiled assembly
    internal void CalculateMetrics()
    {
        // Method implementation
    }
}

Technical Characteristics

  • Explicit Declaration: While top-level types (classes, structs) default to internal if no modifier is specified, methods within a class default to private. The internal keyword must be explicitly applied to a method to grant assembly-wide access.
  • Inheritance and Overriding: A derived class inherits all members of its base class, including internal methods. However, if the derived class is located in an external assembly, it cannot access or invoke the inherited internal method. Furthermore, if an internal method is marked as virtual, it can only be overridden by derived classes located within the same defining assembly.
  • Interface Implementation: An internal method cannot be used to implicitly implement a public interface member. Interface members must be public.

Compound Modifier: protected internal

The internal modifier can be syntactically combined with the protected keyword to create a union of their respective accessibility domains. When a method is declared as protected internal, it is accessible to any code within the same assembly OR to derived classes located in an external assembly.
public class BaseClass
{
    // Accessible assembly-wide, and by derived classes outside the assembly
    protected internal void ProcessData() { }
}
(Note: C# also features a private protected modifier representing the logical intersection of protected and internal access, but it syntactically combines the private and protected keywords, not the internal keyword.)

Bypassing Assembly Boundaries

The strict assembly boundary of an internal method can be explicitly bypassed at the assembly level using the InternalsVisibleTo attribute. This attribute is applied to the defining assembly and specifies the name of a “friend” assembly that is granted access to all internal types and members.
using System.Runtime.CompilerServices;

// Grants the assembly named "ExternalAssembly" access to internal methods
[assembly: InternalsVisibleTo("ExternalAssembly")]

namespace CoreLibrary
{
    public class Engine
    {
        internal void ExecuteInternalRoutine() { }
    }
}
Master C# with Deep Grasping Methodology!Learn More