gpt4 book ai didi

c# - 控制台应用程序输出到 .csv 文件

转载 作者:行者123 更新时间:2023-12-02 15:29:10 25 4
gpt4 key购买 nike

我正在尝试制作一个显示数字的程序:

    1, 10   +30
2, 40 (the scale goes up in this pattern by adding 20 to the last number added)
3, 90 +50
4, 160
5, 250 +70

到目前为止我有这段代码:

 using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace Myloop
{
class Program
{
static void Main(string[] args)
{
FileStream filestream = new FileStream("loopdata.csv", FileMode.Create);
var streamwriter = new StreamWriter(filestream);
streamwriter.AutoFlush = true;
Console.SetOut(streamwriter);
Console.SetError(streamwriter);

int forloop;
for (forloop = 1; forloop < 21; forloop++)
Console.WriteLine(forloop);

Console.ReadLine();

}
}
}

这显示了数字 1 - 20 的第一个序列,但是任何人都可以指导我如何在控制台应用程序中执行它旁边的其他序列吗?以及如何将这些输出到 .csv 文件,因为到目前为止我所掌握的信息没有出现在 .csv 文件中。

最佳答案

首先将控制台输出流式传输到文件

FileStream filestream = new FileStream("loopdata.csv", FileMode.Create);
var streamwriter = new StreamWriter(filestream);
streamwriter.AutoFlush = true;
Console.SetOut(streamwriter);
Console.SetError(streamwriter);

关于c# - 控制台应用程序输出到 .csv 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19717174/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com