String or string?
-
I used to do the same,
string variable
andString.Format(...)
andint variable
andInt32.Parse(...)
. There was a good reason I did that though, Microsoft recommended doing it! Until I switched to Visual Studio 2015 and all of a sudden it started giving me "tips" to simplifyString
tostring
andInt32
toint
... Thanks Microsoft, for sticking to your own guidelines :~ For the same reason I stopped usingthis
andbase
(unless necessary) andTheClassImIn.StaticMethod
instead of simplyStaticMethod
. And yes, I know I can turn off those rules, but I like sticking to defaults :)Best, Sander arrgh.js - Bringing LINQ to JavaScript SQL Server for C# Developers Succinctly Object-Oriented Programming in C# Succinctly
-
Jon McKee wrote:
They could transparently change
int
to map toInt64
in the future, for exampleThey could, but won't. There are way too many things that would go crash-bang-BOOM if they did.
Software Zen:
delete this;
-
I believe the reason it suggests to simplify the name is because
string
,int
, etc do not require theSystem
namespace include whileString
,Int32
, etc still do. It can help clean up your namespace includes if that file doesn't use theSystem
namespace for things other than simple types :thumbsup: I'm sure there are other reasons to suggest simplification but that's the one that immediately comes to mind. EDIT: Now that I think about it, in a way the simple names "decouple" the developer from the exact underlying type too. They could transparently changeint
to map toInt64
in the future, for example.Well, if someone ports .net to an 8-bit OS...
-
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