c#中最高效的string to float
1 public float StrToFloat(object FloatString)
2 {
3 float result;
4 if (FloatString != null)
5 {
6 if (float.TryParse(FloatString.ToString(), out result))
7 return result;
8 else
9 {
10 return (float)0.00;
11 }
12 }
13 else
14 {
15 return (float)0.00;
16 }
17 }
2 {
3 float result;
4 if (FloatString != null)
5 {
6 if (float.TryParse(FloatString.ToString(), out result))
7 return result;
8 else
9 {
10 return (float)0.00;
11 }
12 }
13 else
14 {
15 return (float)0.00;
16 }
17 }
1 public float StrToFloat(object FloatString)
2 {
3 try
4 {
5 float f = (float)Convert.ToSingle(FloatString);
6 return f;
7 }
8 catch (FormatException)
9 {
10 return (float)0.00;
11 }
12 }
2 {
3 try
4 {
5 float f = (float)Convert.ToSingle(FloatString);
6 return f;
7 }
8 catch (FormatException)
9 {
10 return (float)0.00;
11 }
12 }
这是我整理的两种string转float的方法,第一种方法性能比第二种方法好一倍(在dottrace中测试)
请问大家还有更好的string转float的方法吗?