Resharper पता चलता है कि निम्नलिखित से बदला जा:सी # प्रकार तुलना: Type.Equals बनाम ऑपरेटर ==
Type foo = typeof(Foo);
Type bar = typeof(Bar);
if(foo.Equals(bar)) { ... }
करने के लिए:
if(foo == bar) { ... }
ऑपरेटर ==
// Summary:
// Indicates whether two System.Type objects are equal.
//
// Parameters:
// left:
// The first object to compare.
//
// right:
// The second object to compare.
//
// Returns:
// true if left is equal to right; otherwise, false.
public static bool operator ==(Type left, Type right);
बराबर (टाइप ओ)
// Summary:
// Determines if the underlying system type of the current System.Type is the
// same as the underlying system type of the specified System.Type.
//
// Parameters:
// o:
// The System.Type whose underlying system type is to be compared with the underlying
// system type of the current System.Type.
//
// Returns:
// true if the underlying system type of o is the same as the underlying system
// type of the current System.Type; otherwise, false.
public virtual bool Equals(Type o);
प्रश्न
क्यों operator ==
जब प्रकार की तुलना Equals(Type o)
से अधिक की सिफारिश की जाएगी?
आर # आम तौर पर कुछ सुझाव है और एक वैध कारण प्रदान करेगा; इस मामले में यदि वे कार्यात्मक रूप से समकक्ष हैं, तो मुझे संदेह है कि सुझाव पठनीयता के लिए है, जो व्यक्तिपरक है। मुझे आश्चर्य है कि क्या एक और कारण है कि इसका सुझाव दिया जा रहा है? –
@MetroSmurf - R # अक्सर पठनीयता के लिए चीजों का सुझाव देता है (उदाहरण के लिए बयान में घोंसले को कम करना)। –
यह संभवतः इच्छित कारण है, लेकिन चूंकि दोनों इस मामले में कार्यात्मक रूप से समकक्ष नहीं हैं, तो निश्चित रूप से यह रिशेर्पर में एक गलती है? –