String or string?
-
When writing my C# code I was in the habit of using string (all lowercase) for strings declarations, etc. and String (capitalized) for method calls such as String.Empty and String.Format just as a sort of aide memoir that I was calling an object method. As I started to create String extension methods I reviewed this habit of mine and decided this was a pointless differentiation and switched to just using string all the time. At the same time I decided that my using Int32 for methods such as Int32.TryParse and just int in declarations, etc. was also pointless and perhaps confusing to others and so switched to using int all the time instead. It all compiles to the same IL code anyway so it was just a matter of style really. What do you think?
- I would love to change the world, but they won’t give me the source code.
-
They are, just read the documentation! Both implement IComparable and IComparable<T>. They implement some other interfaces too, like IEquatable and IConvertible.
Best, Sander arrgh.js - Bringing LINQ to JavaScript SQL Server for C# Developers Succinctly Object-Oriented Programming in C# Succinctly
-
When writing my C# code I was in the habit of using string (all lowercase) for strings declarations, etc. and String (capitalized) for method calls such as String.Empty and String.Format just as a sort of aide memoir that I was calling an object method. As I started to create String extension methods I reviewed this habit of mine and decided this was a pointless differentiation and switched to just using string all the time. At the same time I decided that my using Int32 for methods such as Int32.TryParse and just int in declarations, etc. was also pointless and perhaps confusing to others and so switched to using int all the time instead. It all compiles to the same IL code anyway so it was just a matter of style really. What do you think?
- I would love to change the world, but they won’t give me the source code.
Given all the confusion, I think I'll just override String and string, in future, with an array (which is all a string is meant to be, anyway).
I wanna be a eunuchs developer! Pass me a bread knife!
-
Cornelius Henning wrote:
I believe at some point in the past this was the case??
Nope, never. It's just an alias.
string
Visual Studio .NET 2003
The string type represents a string of Unicode characters. string is an alias for System.String in the .NET Framework.:thumbsup:
-
When writing my C# code I was in the habit of using string (all lowercase) for strings declarations, etc. and String (capitalized) for method calls such as String.Empty and String.Format just as a sort of aide memoir that I was calling an object method. As I started to create String extension methods I reviewed this habit of mine and decided this was a pointless differentiation and switched to just using string all the time. At the same time I decided that my using Int32 for methods such as Int32.TryParse and just int in declarations, etc. was also pointless and perhaps confusing to others and so switched to using int all the time instead. It all compiles to the same IL code anyway so it was just a matter of style really. What do you think?
- I would love to change the world, but they won’t give me the source code.
What I find amusing is that VS2015 says that
String.Empty
can be simplified tostring.Empty
Riiight. MarcV.A.P.O.R.ware - Visual Assisted Programming / Organizational Representation Learning to code with python is like learning to swim with those little arm floaties. It gives you undeserved confidence and will eventually drown you. - DangerBunny Artificial intelligence is the only remedy for natural stupidity. - CDP1802
-
They are, just read the documentation! Both implement IComparable and IComparable<T>. They implement some other interfaces too, like IEquatable and IConvertible.
Best, Sander arrgh.js - Bringing LINQ to JavaScript SQL Server for C# Developers Succinctly Object-Oriented Programming in C# Succinctly
-
What I find amusing is that VS2015 says that
String.Empty
can be simplified tostring.Empty
Riiight. MarcV.A.P.O.R.ware - Visual Assisted Programming / Organizational Representation Learning to code with python is like learning to swim with those little arm floaties. It gives you undeserved confidence and will eventually drown you. - DangerBunny Artificial intelligence is the only remedy for natural stupidity. - CDP1802
-
I did not mean this Kind of comparable (IComparable etc) :-D I meant compare the two Scenarios :laugh:
I know what you meant, I just to chose to interpret it differently ;p
Best, Sander arrgh.js - Bringing LINQ to JavaScript SQL Server for C# Developers Succinctly Object-Oriented Programming in C# Succinctly
-
I know what you meant, I just to chose to interpret it differently ;p
Best, Sander arrgh.js - Bringing LINQ to JavaScript SQL Server for C# Developers Succinctly Object-Oriented Programming in C# Succinctly
-
When writing my C# code I was in the habit of using string (all lowercase) for strings declarations, etc. and String (capitalized) for method calls such as String.Empty and String.Format just as a sort of aide memoir that I was calling an object method. As I started to create String extension methods I reviewed this habit of mine and decided this was a pointless differentiation and switched to just using string all the time. At the same time I decided that my using Int32 for methods such as Int32.TryParse and just int in declarations, etc. was also pointless and perhaps confusing to others and so switched to using int all the time instead. It all compiles to the same IL code anyway so it was just a matter of style really. What do you think?
- I would love to change the world, but they won’t give me the source code.
For what it's worth, the C# style guidelines on MSDN say to use the lower case.
-
Actually, that's where the problems begin. Lower and upper-case primitives in Java do completely different things.
-
When writing my C# code I was in the habit of using string (all lowercase) for strings declarations, etc. and String (capitalized) for method calls such as String.Empty and String.Format just as a sort of aide memoir that I was calling an object method. As I started to create String extension methods I reviewed this habit of mine and decided this was a pointless differentiation and switched to just using string all the time. At the same time I decided that my using Int32 for methods such as Int32.TryParse and just int in declarations, etc. was also pointless and perhaps confusing to others and so switched to using int all the time instead. It all compiles to the same IL code anyway so it was just a matter of style really. What do you think?
- I would love to change the world, but they won’t give me the source code.
-
If the usage is correct, that make me think why the VS Intellisense still display "name can be simplified", "Show potential fixes", IDE0001 C# Name can be simplified. Isn't that "Show potential fixes" = there is a bug and here is the potential fix? After all VS is Microsoft product right? ;P ;P
Bryian Tan