Quantcast
Channel: C#タグが付けられた新着記事 - Qiita
Viewing all articles
Browse latest Browse all 9691

C# for文を用いてテキストファイルを100個作成する方法

$
0
0
★「1つのフォルダには同じ名前のファイルは作れない」という基本のことに注意 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.IO; namespace for文 //ここはプロジェクト名なのでなんでもよい { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { for (int i = 0; i < 100; i++) { File.CreateText($@"C:\Users\8100825\Documents\ファイル作成_{i.ToString()}.txt"); } } } } 「開始」→「button1」の順に押すと、画像のように、「ドキュメント」フォルダに「ファイル作成_0.txt」~「ファイル作成_99.txt」が作られる。

Viewing all articles
Browse latest Browse all 9691

Trending Articles