-1

I'm wondering how does C# create alias for its classes and structs? E.g.: 'String' class has alias of 'string'. 'Int32' struct has alias of 'int'

John Kugelman
  • 349,597
  • 67
  • 533
  • 578
Conax
  • 69
  • 7
  • 3
    It's just the compiler. There is no alias. The language knows that `string` is just `System.String`. – Enigmativity Nov 14 '20 at 02:52
  • 1
    I don't think this question is a duplicate, and I think you made it clear enough from the title alone that you're asking a different question than any of the supposed duplicates. However, it might still be closed as showing lack of research, because you can probably answer your own question by reading [the source](https://referencesource.microsoft.com/#mscorlib/system/int32.cs). – Kevin Krumwiede Nov 15 '20 at 21:20
  • @KevinKrumwiede That is great! Thank you very much for the location of the source. I had tried to google about it but that link never came up. I believe most people as well as myself always Google first and only post a question here when Google doesn't help. I just failed to list out all the places I've been to in my post. – Conax Nov 17 '20 at 04:17

1 Answers1

1

"int" and "string" are examples of C# language keywords. They are built into the language. The "int32" and "String" aliases are defined in the .NET framework "System" namespace. In order to use these aliases, you need to include a "using System;" statement at the head of your c# file.

John Pankowicz
  • 4,203
  • 2
  • 29
  • 47
  • Thank you for your comment, John. In Visual Studio, if I press F12 over an 'int' keyword, it takes me to the definition of System.Int32 struct. Do you mean on machines with different architectures pressing F12 on an 'int' may redirect to System.Int16 or System.Int64? – Conax Nov 15 '20 at 05:22
  • 2
    Double-checking, I learned that a C# (and C) int nowadays always means int32. I started programming with C on 8 and then 16 bit processors, where the size of an int did change. I edited my post. – John Pankowicz Nov 15 '20 at 21:00