C# - What are the advantages and disadvantages of using String as opposed to string

In a previous question here:


One of the experts mentioned that in some code I posted I should use the language version of "string" rather than the Framework version "String" as I am interested to know what the differences are between the two I have posted it here as a new question.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

I remember seeing that comment and also immediately checking that claim up on Google. I it's evidently just string is an alias of String (which actaully is System.String). This helped me: https://dzone.com/articles/what’s-difference-between-0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
SivAuthor Commented:
Seems like the only advantage of using "string" is it's "recommended", but according to that article you pointed to there is actually no performance difference between the two?

Unless I am missing something!?
Fernando SotoRetiredCommented:
Hi Siv;

There is no difference between String and string. The string is just an alias for String. From Microsoft documentation Strings (C# Programming Guide)

string vs. System.String
In C#, the string keyword is an alias for String. Therefore, String and string are equivalent, and you can use whichever naming convention you prefer. The String class provides many methods for safely creating, manipulating, and comparing strings. In addition, the C# language overloads some operators to simplify common string operations. For more information about the keyword, see string (C# Reference). For more information about the type and its methods, see String.
HTML5 and CSS3 Fundamentals

Build a website from the ground up by first learning the fundamentals of HTML5 and CSS3, the two popular programming languages used to present content online. HTML deals with fonts, colors, graphics, and hyperlinks, while CSS describes how HTML elements are to be displayed.

SivAuthor Commented:
Well thanks to you both for that clarification, I think I will continue to use "String" as I like the way the editor colours it makes it stand out from keywords and helps me keep variables and keywords separate in my own head.
SivAuthor Commented:
Thanks for clarifying this for me.
Fernando SotoRetiredCommented:
Not a problem, glad to help.
ste5anSenior DeveloperCommented:
string is the type name defined by the grammar of C#. String is the type from the .Net framework. They are the same when you use C#and VS. Or better string is an alias for String.

But: this could be changed when necessary. Theoretically.

Consistency: we use mostly all the time for example int instead of System.Int32. Thus we should also do it for string and all types which have an alias.

Syntax: While it's not about string/String.. you can define the enum data type only when you specify the alias name, not the concrete .Net type.
Fernando SotoRetiredCommented:

You need to use the correct .Net type with its alias name for example alias long would be System.Int64. so using the following code will work.
public class EnumTest2
    enum Range : System.Int64 { Max = 123456782L, Min = 12345555L };
    static void Main()
        long x = (long)Range.Max;
        long y = (long)Range.Min;
        Console.WriteLine("Max = {0}", x);
        Console.WriteLine("Min = {0}", y);

Open in new window

Switching this in the code enum Range : System.Int64 { Max = 123456782L, Min = 12345555L }; to this enum Range : long { Max = 123456782L, Min = 12345555L }; will still work.
ste5anSenior DeveloperCommented:
ah, I see. thx.
Fernando SotoRetiredCommented:
Not a problem.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.