String Comparison
string str1 = "Apple"; string str2 = "Æble"; int result1 = String.Compare(str1, str2, CultureInfo.InvariantCulture, CompareOptions.IgnoreCase);
string str1 = "Apple";
string str2 = "Æble";
int result1 = String.Compare(str1, str2);
Do
const string input = "interesting";
bool result =input.Equals("INTERESTING", StringComparison.InvariantCultureIgnoreCase);
Don't
const string input = "interesting";
bool comparison = input.ToUpper() == "INTERESTING";
Do
string newString = s.ToUpper(CultureInfo.InvariantCulture);
Don't
string newString = s.ToUpper();
String Sorting
StringComparer invCmp = StringComparer.InvariantCulture;
var str=new List<string> {"a", "b", "c"};
str.Sort(invCmp);
Don't
var str=new List<string> {"a", "b", "c"};
str.Sort();
Number Formatting
int i = 100;
string res = i.ToString(CultureInfo.InvariantCulture);
string res2 = Convert.ToString(CultureInfo.InvariantCulture);
Don't
int i = 100;
string res = i.ToString();
string res2 = Convert.ToString();
Do
double number = 123.456;
string convertToString = Convert.ToString(number, CultureInfo.InvariantCulture);
string numberToString = number.ToString(CultureInfo.InvariantCulture);
string stringFormat = String.Format(CultureInfo.InvariantCulture, "{0}", number);
Don't
double number = 123.456;
string convertToString = Convert.ToString(number);
string numberToString = number.ToString();
string stringFormat = String.Format("{0}", number);
Calendar Differences
Date Formatting
string s1 = "10/31/2012";
DateTime date = DateTime.Parse("10 / 31 / 2012", CultureInfo . InvariantCulture);
Don't
string s1 = "10/31/2012";
DateTime date = DateTime.Parse("10 / 31 / 2012");
Do
string datenew = Convert.ToDateTime("10/31/2012", CultureInfo.InvariantCulture).ToString();
Don't
string datenew = Convert.ToDateTime("10/31/2012").ToString();
Do
DateTime datenew = Convert.ToDateTime("10/31/2012", CultureInfo.InvariantCulture);
Don't
DateTime datenew = Convert.ToDateTime("10/31/2012");
Time Formatting
Do
string conv = DateTime.Now.ToShortTimeString();
DateTime newDate = DateTime.Parse(conv, CultureInfo.InvariantCulture);
Don't
string conv = DateTime.Now.ToShortTimeString();
DateTime newDate = DateTime.Parse(conv);
Currency Formatting
string conv2 = "12,34,56,789.00";
decimal newd = Convert.ToDecimal(conv2,CultureInfo.InvariantCulture);
Don't
string conv2 = "12,34,56,789.00";
decimal newd = Convert.ToDecimal(conv2);
No comments:
Post a Comment