11

From the link ( which is mentioned in Question) my question is that microsoft says "The C# type keywords and their aliases are interchangeable" But why we need Aliases, From my point of view Boolean is more meaningful then bool and Int32 is more meaningful then int then why aliases ???

Community
  • 1
  • 1
Asim Sajjad
  • 2,526
  • 10
  • 36
  • 73

4 Answers4

10

Because C# tries to be a bit like C/C++ for familiarity. You are welcome to use the long names if you wish, but I think most people prefer the short names.

Mark Byers
  • 811,555
  • 193
  • 1,581
  • 1,452
5

Because in C[1] and C++ the data types are named as bool and int, and C# is designed based on C / C++.

Also Boolean and Int32 are names from the .NET framework which is shared by all CLR languages, but individual language may define their own aliases (e.g. Boolean and Integer in VB.net) to accommodate for the "feel" of that language.

[1]: C99 / with stdbool.h

kennytm
  • 510,854
  • 105
  • 1,084
  • 1,005
5

Because programmers are lazy and Microsoft wants to do them a favour.

I prefer the long names but most former C++ programmers will be used to string, int, float and double.

  • 2
    I believe it's even in MS's style guidelines (StyleCop) to use the built-in aliases int, string etc instead of the full typename. – Andy Shellam Mar 18 '10 at 12:32
  • For laziness I prefer `str` over `string` :p – kennytm Mar 18 '10 at 12:35
  • -1 for thinking Microsoft wants to do programmers any favours. – PP. Mar 18 '10 at 12:47
  • Microsoft has a few thousand developers and many of them are or will be developing using .NET so it's in their own interest to be nice to the programmers using it. –  Mar 18 '10 at 12:58
2

Because the "System.Boolean" is a value type from mscorlib.dll and the "bool" is keyword from C#. If you want, you can specify your own assembly instead of mscorlib which will implement "bool", "byte", "sbyte", "int", etc...

TcKs
  • 25,849
  • 11
  • 66
  • 104
  • 8
    dear god. I hope I never encounter a piece of code that has felt the need to do that... – Paddy Mar 18 '10 at 12:21
  • So where do you answer "why we need Aliases"? – Kamarey Mar 18 '10 at 12:22
  • @Paddy: I used it once for special compact framework application. Bud yes - it was very special solution. – TcKs Mar 18 '10 at 12:29
  • @Kamarey: We don't need it. It isn't aliases in core. The "bool" specified bollean data type in c# language (which can be implemented in another enviroment than .NET) and the "System.Boolean" is type (struct) in some assembly which c# compiler use to map to "bool" keyword from C#. – TcKs Mar 18 '10 at 12:31
  • 1
    The C# spec defines `bool` as an alias for `System.Boolean`. While it may be possible to hack/change this yourself, the resulting language would not be spec-compliant C#. – LukeH Mar 18 '10 at 13:26