2016-03-24 25 views
-2
public string readFile() 
    { 
     string text; 
     using (var streamReader = new  StreamReader("c:/aaa/balance.txt",Encoding.UTF8)); 
     { 
      text = streamReader.ReadToEnd(); 
     } 
     return text; 
    } 
    public double sumOfPlus() 
    { 
     double sum = 0; 
     string text = readFile(); 
     string[] arr = text.Split(','); 
     for (int i = 0; i < arr.Length; i++) 
     { 
      sum += Convert.ToDouble(arr[i]); 

     } 
     return sum; 
    } 
    } 

我不能得到總和的輸出,文件中的數字是有效的。
我得到的轉換線錯誤的說:它不是complibate格式模式從字符串轉換爲雙重不工作在C#

+1

'itws的不complibate pattern'它肯定它不是這個消息.... – Eser

+0

你從該文件中輸入的格式是有缺陷的。 –

+0

我需要做什麼?改變它浮動? –

回答

1

試試這個

string[] arr = text.Split(new []{",", " "},StringSplitOptions.RemoveEmptyEntries); 

代替

string[] arr = text.Split(','); 
+0

非常感謝,我不知道這個選項。 –

+0

現在有效嗎? –

+0

是的。 thanx –