Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question What is an "internal object"?

Discussion in 'Scripting' started by TiggyFairy, Sep 17, 2023.

  1. TiggyFairy

    TiggyFairy

    Joined:
    Dec 22, 2019
    Posts:
    417
    While messing about in c#, Visual studio auto-suggested this:
    internal object thing;


    I know what the internal part means, but I can't find any reference to what the object means. Any ideas?
     
  2. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,379
    Without more context I can't be certain exactly what you're talking about.

    But from what context you've given I'm assuming it suggested a field/variable declaration and that declaration is something like:
    Code (csharp):
    1. class SomeCodeContext
    2. {
    3.     internal object thing;
    4. }
    internal - you said you already know what that means, but I'll link anyways:
    https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/internal

    object - C# shorthand for System.Object, the type from which all types inherit and thusly can be cast as (value types get boxed of course):
    https://learn.microsoft.com/en-us/dotnet/api/system.object?view=net-7.0

    thing - name of the field/variable.

    So you just declared a field/variable named 'thing' of type 'System.Object' that is accessible with the access modifier internal.

    As to why VS auto-suggested it? :shrug: I would need more context.
     
    TiggyFairy, Bunny83 and orionsyndrome like this.
  3. Bunny83

    Bunny83

    Joined:
    Oct 18, 2010
    Posts:
    3,524
    Great you mention it here because many seems to get this wrong. C# has "alias names" for certain CLR types and "object" is one of them. Other more common ones are
    int
    (System.Int32),
    string
    (System.String),
    long
    (System.Int64),
    float
    (System.Single) and
    double
    (System.Double) which are also just alias names of the language for convenience. Technically you actually use the types from the System namespace.