c# - String equals does not work with string formatted numbers -



c# - String equals does not work with string formatted numbers -

how can strings have different hash codes same text value of "16 777 216"?

the test method not pass:

using system; using system.text; using system.collections.generic; using system.linq; using microsoft.visualstudio.testtools.unittesting; namespace unitteststringequals { [testclass] public class formattertests { [testmethod] public void double_test_1() { assert.areequal("16 777 216", formatdoublewiththousandseparator(16777216, 0)); } public string formatdoublewiththousandseparator(double value, int digits) { double result = math.round((double)value, digits); system.globalization.numberformatinfo nfi = (system.globalization.numberformatinfo)system.globalization.numberformatinfo.invariantinfo.clone(); nfi.numbergroupseparator = " "; homecoming result.tostring("###,###,###,###,###,###,##0.#####", nfi); } } }

because 2 strings not same object, not equal, there string comparision method should used instead.

make sure isn't case 1 string has non-printing character , other 1 not. have remember string object. need compare value of said object value of object.

http://msdn.microsoft.com/en-us/library/system.string.equals.aspx http://msdn.microsoft.com/en-us/library/1hkt4325.aspx

c# unit-testing string-formatting

Comments

Popular posts from this blog

How do I check if an insert was successful with MySQLdb in Python? -

delphi - blogger via idHTTP : error 400 bad request -

postgresql - ERROR: operator is not unique: unknown + unknown -