测试代码
static void Main(string[] args) { string[] ss = new string[]{ "", " ", " ", string.Empty }; for (int i = 0; i < ss.Length; i++) { for (int j = i+1; j < ss.Length; j++) { bool re=false; if (ss[i] == ss[j]) re = true; Console.WriteLine("{0}与{1}是否相等{2}", i.ToString(), j.ToString(), re.ToString()); } } Console.ReadLine(); for (int i = 0; i < ss.Length; i++) { try { double p = Convert.ToDouble(ss[i]); Console.WriteLine("{0} {1}", i.ToString(), p.ToString()); } catch (System.Exception ex) { continue; } } Console.ReadLine(); for (int i = 0; i < ss.Length; i++) { try { double p; double.TryParse(ss[i], out p); Console.WriteLine("{0} {1}", i.ToString(), p.ToString()); } catch (System.Exception ex) { continue; } } Console.ReadLine(); }