Created
October 25, 2017 13:20
-
-
Save mrgarita/b8f79020012a98fe682650249d6c3cea to your computer and use it in GitHub Desktop.
C#:CSVファイルに書き出す
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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