Skip to content

Instantly share code, notes, and snippets.

@mrgarita
Created October 25, 2017 13:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrgarita/b8f79020012a98fe682650249d6c3cea to your computer and use it in GitHub Desktop.
Save mrgarita/b8f79020012a98fe682650249d6c3cea to your computer and use it in GitHub Desktop.
C#:CSVファイルに書き出す
using System;
using System.IO;
using System.Text;
namespace CSVファイルに書き出す
{
class Program
{
static void Main(string[] args)
{
string[] words = new string[] { "apple", "りんご", "lemon", "レモン", "kiwi", "キウイ", "peach", "" };
try
{
// ファイルを書き込み型式(上書き)で開く
StreamWriter file = new StreamWriter("tango.txt", false, Encoding.UTF8);
for(int i=0; i<words.Length; i += 2)
{
file.WriteLine(string.Format("{0},{1}", words[i], words[i + 1]));
}
file.Close();
Console.WriteLine("ファイルに書き込みました");
}
catch (Exception e)
{
Console.WriteLine(e.Message); // エラーメッセージを表示
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment