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

In a previous question here:

http://www.experts-exchange.com/questions/28711852/C-writing-to-Access-DB-getting-duplicates-error.html#a40966150

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.
SivAsked:
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.

MlandaTCommented:
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
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!?
0
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.
0
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

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.
0
SivAuthor Commented:
Thanks for clarifying this for me.
0
Fernando SotoRetiredCommented:
Not a problem, glad to help.
0
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.
0
Fernando SotoRetiredCommented:
@ste5an;

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.
0
ste5anSenior DeveloperCommented:
ah, I see. thx.
0
Fernando SotoRetiredCommented:
Not a problem.
0
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
C#

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.