locked
Is there a difference between capitalized types and non capitalized types? RRS feed

  • Question

  • I just noticed that often times types in C# are offered (via intellisense) in Capitalized and non-capitalized.  I tried to do a search to find the answer, but couldn't find anything. Nothing mentioned in my reference books either.

    ie: String vs string or Decimal vs decimal

    Is there a difference between the two?
    Why are there two types?

    Thanks?

    Monday, October 19, 2009 10:31 PM

Answers

  • The C# language specifies some aliases for specific types:

    string is an alias for System.String
    double
    is an alias for System.Double

    In general, the lower case type name is the C# language specific type.  The upper case name is the .NET framework name for the type, which will likely be in the System namespace.

    When this is compiled, the C# creates exactly the same IL.  However, the lower case name has some advantages - it's shorter to type, and can be used even if you don't import the System namespace (using System;).

    Unless you import the System namespace, you'd have to type "System.String myString;".


    Reed Copsey, Jr. - http://reedcopsey.com
    • Marked as answer by MTech8 Monday, October 19, 2009 11:01 PM
    Monday, October 19, 2009 10:46 PM
    • Marked as answer by MTech8 Monday, October 19, 2009 11:01 PM
    Monday, October 19, 2009 10:47 PM
  • For string and decimal - no; through the object heirarchy they end up as the same type.  The lowercase "string" is an IDE keyword.  The capatalized "String" the fully qualified namespace (found as System.String).  The same applies to decimal. 

    But, just a note - C# is case-sensitive.  If you have a type "someclass" and another type "Someclass," they are not the same.  The exception is your example, where the lowercase version is a recognized keyword.
    • Marked as answer by MTech8 Monday, October 19, 2009 11:01 PM
    Monday, October 19, 2009 10:49 PM
  • As well as float, double, long, int, char, byte.  And the ones with a question mark behind them (eg decimal?), syntax sugar for Nullable<>.  Saves the fingers, keeps 'C' and Java programmers happy.  And me.

    Hans Passant.
    • Marked as answer by MTech8 Monday, October 19, 2009 11:01 PM
    Monday, October 19, 2009 10:54 PM

All replies

  • The C# language specifies some aliases for specific types:

    string is an alias for System.String
    double
    is an alias for System.Double

    In general, the lower case type name is the C# language specific type.  The upper case name is the .NET framework name for the type, which will likely be in the System namespace.

    When this is compiled, the C# creates exactly the same IL.  However, the lower case name has some advantages - it's shorter to type, and can be used even if you don't import the System namespace (using System;).

    Unless you import the System namespace, you'd have to type "System.String myString;".


    Reed Copsey, Jr. - http://reedcopsey.com
    • Marked as answer by MTech8 Monday, October 19, 2009 11:01 PM
    Monday, October 19, 2009 10:46 PM
    • Marked as answer by MTech8 Monday, October 19, 2009 11:01 PM
    Monday, October 19, 2009 10:47 PM
  • For string and decimal - no; through the object heirarchy they end up as the same type.  The lowercase "string" is an IDE keyword.  The capatalized "String" the fully qualified namespace (found as System.String).  The same applies to decimal. 

    But, just a note - C# is case-sensitive.  If you have a type "someclass" and another type "Someclass," they are not the same.  The exception is your example, where the lowercase version is a recognized keyword.
    • Marked as answer by MTech8 Monday, October 19, 2009 11:01 PM
    Monday, October 19, 2009 10:49 PM
  • As well as float, double, long, int, char, byte.  And the ones with a question mark behind them (eg decimal?), syntax sugar for Nullable<>.  Saves the fingers, keeps 'C' and Java programmers happy.  And me.

    Hans Passant.
    • Marked as answer by MTech8 Monday, October 19, 2009 11:01 PM
    Monday, October 19, 2009 10:54 PM
  • Thanks everyone for your replies.

    I definitely understand this now. Greatly appreciated.
    Monday, October 19, 2009 11:01 PM
  • Provides a collection of methods for allocating unmanaged memory, copying unmanaged memory blocks, and converting managed to unmanaged types, as well as other miscellaneous methods used when interacting with unmanaged code.
    Monday, September 21, 2020 11:46 AM