我制作了一个快速程序,所以我可以从collatz猜想中获取数据到图表,我正在尝试将其写入csv,其中第1列的结果数量和第2列中的步骤数量。但是由于某种原因,streamwriter只输出每行的第一行。如何在写入CSV文件之前让流程图更新?
static void Main(string[] args)
{
int y;
BigInteger x;
System.Collections.ArrayList ResultsArray = new System.Collections.ArrayList();
System.IO.StreamWriter file = new System.IO.StreamWriter(@"C:\Users\public\testfolder\writelines2.csv");
x = BigInteger.Pow(15, 15);
y = 1;
var ColumnWriter = string.Format("{0},{1}",x, y);
do
{
if (x % 2 != 0)
{
x = (x * 3) + 1;
Console.WriteLine(x);
ResultsArray.Add(x);
}
else
{
x = (x / 2);
Console.WriteLine(x);
ResultsArray.Add(x);
}
file.WriteLine(ColumnWriter);
y = y + 1;
} while (x > 1);
file.Flush();
Console.ReadLine();
}
}
}
答案 0 :(得分:1)
您不更新循环内的字符串变量ColumnWriter。放
.image{
width:300px;
height:500px;
background-color: blue;
}
.leftImage{
margin-top: 20px;
float:left;
width:300px;
height: 500px;
}
.rightImage{
margin-top: 20px;
float:right;
width:300px;
height: 500px;
margin-left: 20px;
}
.textRight{
background-color: blanchedalmond;
height:150px;
padding: 80px;
padding-top: 60px;
padding-bottom: 120px;
margin-left: 250px;
}
.textLeft{
background-color: blanchedalmond;
height:150px;
padding: 80px;
padding-top: 60px;
padding-bottom: 120px;
margin-right: 250px;
}
#wrap{
margin-top: 160px;
margin-bottom: 100px;
width: 100%;
min-height: 200px;
min-width: 900px;
}
之前或之后(取决于您要输出的内容/时间)行
ColumnWriter = string.Format("{0},{1}",x, y);