C#.NET CASE-INSENSITIVE STRING

Chintoo Semi

Total Post:135

Points:947
Posted by  Chintoo Semi
C# 
C#
 1903  View(s)
Ratings:
Rate this:

Hi Expert!

A quick and simple question...

Why does C#.Net allow the declaration of the string object to be case-insensitive?

String sHello = "Hello";
string sHello = "Hello";
Both the lower-case and upper-case S of the word String are acceptable and this seems to be the only object that allows this.

Can anyone explain why?

  1. AVADHESH PATEL

    Post:604

    Points:4228
    Re: C#.Net case-insensitive string

    Hi Chintoo!


    Read below line carefully, that remove your doubt between "string" and "String" 

    "string" is a language keyword while "System.String" is the type it aliases.

    Both compile to exactly the same thing, similarly:

    int is System.Int32
    long is System.Int64
    float is System.Single
    double is System.Double
    char is System.Char
    byte is System.Byte
    short is System.Int16
    ushort is System.UInt16
    uint is System.UInt32
    ulong is System.UInt64

    I think in most cases this is about code legibility - all the basic system value types have aliases, I think the lower case string might just be for consistency.

  1. Shankar M

    Post:25

    Points:175
    Re: C#.Net case-insensitive string

    Hi Chintoo,


    string and String are equivalent in C#.

    Hope the below link might help you understand

    http://en.csharp-online.net/CSharp_String_Theory%E2%80%94string_versus_String

    Regards,
    Shankar

      Modified On Feb-21-2013 03:53:14 AM

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!