我正在將信息寫入文件,並將其命名爲"//Average+DateTime.txt"
;我想我的代碼會更容易比我想澄清:輸出文本文件
String path=bama();
if(path.Contains(".txt")) {
StreamWriter sw=
new StreamWriter(
"C:/Users/msilliman11/Average"
+DateTime.Now.ToString("yyyyMMdd")
+".txt"
);
}
String ElementsNum=RoundedValues.Count.ToString();
DateTime dt=System.DateTime.Now;
using(var NewFile=File.Create(path)) {
using(var writeIt=new StreamWriter(NewFile)) {
writeIt.Write(
"NA"+","
+dt.Hour.ToString()+","+dt.Minute+","
+dt.Day+","+dt.Month.ToString()+","+dt.Year.ToString()+","
+"ALTEST "+","+"ALTEST "+","+heatgrade
+" "+","+" "+","+heatname+","
+DT2.Columns[3].ToString()+","+heatgrade+","
+"OE2"+","+","+","+","+","+","+","+" "+ElementsNum+","
);
foreach(
var pair in
RoundedValues.Zip(
Elements, (a, b) => new {
A=a,
B=b
})) {
writeIt.Write(pair.B.ToString()+","+pair.A.ToString()+",");
}
}
}
我的問題是,我需要命名"Average"
文件,並在寫入文件外使用的代碼塊...
我敢壞在解釋這些問題,但基本上即時通訊試圖讓第二塊使用的信息,被命名爲輸出文件中"4222013Average.txt"
...
您在第一「命名它作爲//Average+DateTime.txt說:」然後你提到的「命名‘4月22日/ 2013Average.txt’,所以它的格式是你想要的嗎? – 2013-04-23 01:18:10
對不起,最後一個是正確的,我把斜線放在那裏也犯了一個錯誤, – 2013-04-24 20:51:44