PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, June 26, 2022

[FIXED] How are type aliases resolved when the System directive is missing?

 June 26, 2022     c#, compiler-errors, directive, types     No comments   

Issue

bool,int,andstring (to name a few), are all aliases of System types.
They can all be used without the System directive being included.
Yet the types they alias can't be used without the System directive.

public class Test
{
    public static void Main()
    {
        bool b;     //valid
        Boolean b2; //compiler error

        int i;      //valid
        Int32 i2;   //compiler error

        string s;   //valid
        String s2;  //compiler error
    }
}

I have few questions as to why this works.

  • Is the compiler making an exception for these commonly used types?

  • Is the System directive being looked at to determine the aliasing, but not being looked at for the other types?

  • Is it always safe to use bool, int,string, etc without the System directive?


Solution

Is the compiler making an exception for these commonly used types?

Yes.

Is the System directive being looked at to determine the aliasing, but not being looked at for the other types?

Yes. Well, sort of. There is no System directive. There is a using directive, with which you can import the System namespace, which defines the types.

Is it always safe to use bool, int,string, etc without the System directive?

Yes.

Many modern languages like C# are heavily inspired from C++, which is in turn heavily inspired from C. The C language had taken the innovative stance of complete separation between compiler and runtime. The compiler of C was (is) making absolutely no assumptions about the standard libraries. In theory, it is possible to write C programs that do not include the standard libraries.

However, languages like C# accept that there is significant merit in having a certain degree of collusion between the compiler and the runtime. Many C# keywords depend on support from the runtime. A very good example of that, the yield return keyword. Other examples are the types that your question is asking about.



Answered By - Mike Nakis
Answer Checked By - Marilyn (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing