Siv
asked on
C# - What are the advantages and disadvantages of using String as opposed to string
In a previous question here:
https://www.experts-exchange.com/questions/28711852/C-writing-to-Access-DB-getting-duplicates-error.html?anchorAnswerId=40966150#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.
https://www.experts-exchange.com/questions/28711852/C-writing-to-Access-DB-getting-duplicates-error.html?anchorAnswerId=40966150#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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.
ASKER
Thanks for clarifying this for me.
Not a problem, glad to help.
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.
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.
@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.
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);
}
}
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.
ah, I see. thx.
Not a problem.
ASKER
Unless I am missing something!?