什么是我缺乏的代码? C#控制台应用程序 [英] what is my lacking code? C# console application
本文介绍了什么是我缺乏的代码? C#控制台应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Random pin = new Random();
for (int i = 1; i <= 1; i++)
{
string path = @"D:\try\"+pin+".txt;"
Console.WriteLine(pin.Next(59372));
using (StreamWriter writer = new StreamWriter(path))
{
writer.WriteLine(pin);
}
}
}
}
路径中没有输出...
no output in path...
推荐答案
Random是一个提供产生随机序列的函数的类。请参阅随机类 [ ^ ]。br />
总是建议查找类帮助文件。
pin
本身不能用来做... string + pin ...
。
您必须先获取一个随机数并存储在变量中。将该变量用于您的文件名并存储在文件中。
干杯
Andi
Random is a class that provides functions to produce random sequences. See examples in Random Class[^].
It's always advised to look up the class help files.
pin
for itself can not be used to do...string + pin...
.
You have to get a random number first and store in a variable. Use that variable for your file name and for storing in the file.
Cheers
Andi
static void Main(string[] args)
{
Random pin = new Random();
string path = @"C:\test.txt";
using (StreamWriter writer = new StreamWriter(path))
{
for (int i = 0; i <= 1; i++)
{
Console.WriteLine(pin.Next(59372));
writer.WriteLine(pin.Next(59372));
}
}
}
这篇关于什么是我缺乏的代码? C#控制台应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文