我想這類型的自動編寫一個程序,從1000至9999,當每個數字輸入,程序應該按enter鍵模擬在C#中一個按鍵
例如,如果我運行該程序,然後打開記事本,輸出應該是:
1000
1001
1002
1003
.
.
.
9998
9999
編輯: 我只是想給一個鍵,按程序的虛擬代碼,並釋放鍵。 就是這樣。
坦對你的答案:)
我想這類型的自動編寫一個程序,從1000至9999,當每個數字輸入,程序應該按enter鍵模擬在C#中一個按鍵
例如,如果我運行該程序,然後打開記事本,輸出應該是:
1000
1001
1002
1003
.
.
.
9998
9999
編輯: 我只是想給一個鍵,按程序的虛擬代碼,並釋放鍵。 就是這樣。
坦對你的答案:)
int i;
int number = 999;
for (i = 0; i < 9000; i++)
{
number += 1;
Console.WriteLine(number);
}
Console.ReadKey();
,你可以把它寫與有System.IO.File類文件,或者你可以將其列表添加到列表,並寫入文件
好吧,如果我們加:
using System.IO;
這將使可使用此.NET類在我們 類接下來讓做一個列表,所有的數字寫入。
List<string> print = new List<string>();
現在,填補了我國在循環內部列表中,我們可以添加
print.add(number.ToString());
好我們的名單已滿,我們所要做的就是將它保存到一個文件
System.IO.File.WriteAllLines(@"C:\users\public\numbers.txt", print);
這將創建我們的文件,我們應該做的!打開它在C:\用戶\公用文件夾中
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
namespace ConsoleApplication14
{
class Program
{
static void Main(string[] args)
{
int i;
int number = 999;
List<string> print = new List<string>();
for (i = 0; i < 9000; i++)
{
number += 1;
print.Add(number.ToString());
}
System.IO.File.WriteAllLines(@"C:\users\public\numbers.txt", print);
Console.WriteLine("Press a button and open your text document");
Console.ReadKey();
}
}
}
你有什麼試過?如果你不顯示任何努力,人們不會幫助你。 – 2015-04-03 13:15:15
你不需要模擬按鍵,你只需要在每個數字後加一個換行。即'.... Write(num + Environment.NewLine)' – Jonesopolis 2015-04-03 13:16:18
我是一個新用戶。請幫我:( – Cyanogen 2015-04-03 13:17:59