我一直在寻找几个小时,我似乎无法找到这个问题的答案.我想生成一个6位数的随机数.有些人可能会告诉我使用这段代码:
Random generator = new Random();
int r = generator.Next(100000, 1000000);
Run Code Online (Sandbox Code Playgroud)
但这限制了我的6位数都超过了10万的价值.我希望能够使用000 001,000 002等生成一个int.之后我想将此整数转换为字符串.
我一直在寻找大约一个小时,根本无法找到任何解决方案.我希望我的.txt文件中的每一行都添加到我的列表中,只要它以相同的数字开头即可.问题在于"line.Substring(0,1)",我不知道如何解决它.也许你明白我想要实现的目标.
using (StreamReader file = new StreamReader(schedulePathDays))
{
string line;
while ((line.Substring(0, 1) = file.ReadLine()) == thisDay.ToString())
{
exercisesRow.Add(line);
}
}
Run Code Online (Sandbox Code Playgroud) 我对 C# 和编程的总体经验几乎为零,所以你可能会觉得我的问题很愚蠢。然而,我尝试使用代码创建一个 Windows 窗体,并且我已经成功实现了我想要的。但现在我想向我的所有按钮添加按钮单击事件。我想要 addToDay[i] 清除exerciseBox[i]、setBox[i] 和repBox[i] 中的文本。谢谢。
public NewSchedule2(string path)
{
InitializeComponent();
this.SuspendLayout();
labels = new System.Windows.Forms.Label[7];
exercises = new System.Windows.Forms.TextBox[7];
sets = new System.Windows.Forms.TextBox[7];
reps = new System.Windows.Forms.TextBox[7];
addToDay = new System.Windows.Forms.Button[7];
string[] lines = File.ReadAllLines(path);
for (int i = 0; i < 7; i++)
{
this.labels[i] = new System.Windows.Forms.Label();
this.labels[i].Location = new System.Drawing.Point(40, 40 + i * 50);
this.labels[i].Name = "Label" + i;
this.labels[i].Size = new System.Drawing.Size(110, 20);
this.labels[i].Text = lines[i];
this.Controls.Add(this.labels[i]);
if (lines[i] == "Restday") …Run Code Online (Sandbox Code Playgroud) c# ×3
button ×1
for-loop ×1
list ×1
streamreader ×1
text ×1
textbox ×1
while-loop ×1
winforms ×1