5

Here are a list of aliases in C# (compliments of What is the difference between String and string in C#?):

object:  System.Object
string:  System.String
bool:    System.Boolean
byte:    System.Byte
sbyte:   System.SByte
short:   System.Int16
ushort:  System.UInt16
int:     System.Int32
uint:    System.UInt32
long:    System.Int64
ulong:   System.UInt64
float:   System.Single
double:  System.Double
decimal: System.Decimal
char:    System.Char

I can see bool through char being lowercase aliases, because they are primitive types.

Why are object and string not capitalized, since they are complex types? Is this an oversight by the developers, or is there a necessary reason for them to be lowercase? Or is this an opinionated question?

You end up with things like string.Format() instead of String.Format(), which just look funky and make me think string is a variable.

Community
  • 1
  • 1
Evorlor
  • 7,263
  • 17
  • 70
  • 141
  • 3
    to be more like C++? adopters could continue using C# as they were used to doing it in previous languages? – ps2goat Jun 08 '15 at 15:18
  • You *can* still write `String.Format()`, assuming you have a `using System;`. – crashmstr Jun 08 '15 at 15:20
  • 1
    Also C# drew a lot of conventions and approaches very similar to Java, which has a very similar structure. It can be kind of confusing when dealing with boxing/unboxing, as sometimes people get the impression one is boxed and one is unboxed, but that is not the case. – AaronLS Jun 08 '15 at 15:21
  • 1
    it seems to me that this has been discussed in multiple different questions with *thousands* of votes; not sure that another question on the same topic is going to create any further clarification. – Claies Jun 08 '15 at 15:23
  • 2
    @Claies : then just flag the post as duplicate, with a link to one of those thousands. – thomasb Jun 08 '15 at 15:27
  • 1
    Well if they capitalized the keyword then it would conflict with the `String` class, so the class would need to be renamed (or all uses of it would require an `@`). – Servy Jun 08 '15 at 15:38
  • 1
    @Servy : I guess the point of the question is "why are there aliases for the 'basic types' when they bring nothing except they're lowercase ?" – thomasb Jun 08 '15 at 15:52
  • @cosmo0 But that's *not* what the question is asking. – Servy Jun 08 '15 at 15:59
  • @Servy True. As an aside, why are you answering the question in a comment ? – thomasb Jun 08 '15 at 16:00

4 Answers4

11

Because all keywords (reserved identifiers) are lowercase.

Sehnsucht
  • 5,019
  • 17
  • 27
  • While that might not be the "original" reason (maybe @EricLippert) sees/knows this, I think the "for consistency" argument is not the worst. (One might ask though: why are all keywords lowercase :-). – Christian.K Jun 08 '15 at 15:25
  • @Christian.K, because C# derives much of its syntax from Java which derived much of its syntax from C, both of which use lower case fro keywords. – David Arno Jun 08 '15 at 15:37
  • @DavidArno: Thanks, but I knew. I was just trying to push the envelope for those that don't :-) – Christian.K Jun 08 '15 at 15:40
  • Going beyond this requires reading minds and mind-reading is frowned upon around here. – OldFart Jun 08 '15 at 15:44
4

In C#, there are no "primitive types" and "complex types". There are classes and structs, (reference types and value types, respectively) among others. Both can include methods (e.g. char.IsDigit('a')). So your objections aren't really valid. But there is still the question: why?

I'm not sure if there's a good source for this, but I think the lowercase aliases are done to match the other C# keywords, which are themselves modeled on C/C++ keywords.

Tim S.
  • 55,448
  • 7
  • 96
  • 122
2

Regarding your last comment:

You end up with things like string.Format() instead of String.Format(), which just look funky and make me think string is a variable.

With C# 6, this becomes a moot point as you can do:

using static System.String;

...
var x = Format(...);

Or going further, you can do away with string.Format altogether and use $ instead.

David Arno
  • 42,717
  • 16
  • 86
  • 131
-1

Answer is simple. If you want to use it like a class use String, if you want to use it like a keyword use string. Developers wanted to make us feel like we are using a primitive type. Because in C# nothing is primitive.

Aishwarya Shiva
  • 3,460
  • 15
  • 58
  • 107