Comments (7)
This documentation from Microsoft also speaks against using == for comparison so I think we should keep it.
from atc-coding-rules.
As far as I understand using ==
for comparing two strings will be the same as using string.Equals()
with StringComparison.Ordinal
(given that the two strings are of type string, and not cast to e.g. object).
In my mind, this way of comparing strings are by far the most commonly used, so applying the MA0006 rule in general would add a lot of clutter.
In most cases I think it would be very obvious if you need to compare using case-insensitivity or the CurrentCulture, and then use the string.Equals()
instead.
from atc-coding-rules.
What StringComparison
style is used with a == b
? If it is not StringComparison.Ordinal
, then a.Equals(b, StringComparison.Ordinal
will perform better.
Besides that, I agree that it does NOT improve readability.
from atc-coding-rules.
Please red comment from cjacobsen.
from atc-coding-rules.
As far as I understand using
==
for comparing two strings will be the same as usingstring.Equals()
withStringComparison.Ordinal
That's surprising to me @rickykaare, but you are right, at least if we read the latest string.cs code. Here we see that EqualsHelper
is called when from both the operators ==
/!=
and from the Equals
method when StringComparison.Ordinal
is set.
That takes the performance concern out of the equation for me. The question that is left is whether we want to be explicit in our code about our intentions, e.g. signaling that, yes, we have thought about culture and this is what we want.
from atc-coding-rules.
ROOT=NONE, because in most cases we are only doing ordinal comparisons anyway, and == leads to cleaner code.
Exception to this rule when working on an application that is multi cultured.
from atc-coding-rules.
from atc-coding-rules.
Related Issues (20)
- NSubstitute.Analyzers.CSharp HOT 4
- Rule: SA1122 UseStringEmptyForEmptyStrings HOT 3
- dotnet pack fails with SymbolPackageFormat property HOT 1
- Align distribution MSBuild files with Atc.Cosmos
- Microsoft.CodeAnalysis.NetAnalyzers should only be included when using older SDKs HOT 1
- CA1812: Avoid uninstantiated internal classes HOT 1
- Test rule: CA1068: CancellationToken parameters must come last HOT 4
- Rule: CA1002 replaces MA0016 HOT 2
- SA1202 (ElementsMustBeOrderedByAccess) should be covered by decision for SA1201 HOT 2
- Consider all StyleCop Documentation Rules HOT 2
- Semantic versioning of the ATC Rules
- Rule: CA1305 replaces MA0011 HOT 1
- Rule: MA0038 Make method static - Same as CA1822 HOT 1
- Rule: SA1601
- Rule: IDE0060
- Directory.Build.props streamline
- Rule: csharp_style_prefer_index_operator and csharp_style_prefer_range_operator
- Rule: IDE0161 - File-scoped namespace
- Rule: CA1602
- Rule: IDE0005
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from atc-coding-rules.