bloggerads

2013年1月1日 星期二

C# : Write TXT file

Write a struct to a TXT file

struct test{
    public char a;
    public int x;
    public int y;
    public int z;
}

static void Main(string[] args)
{
    test[] aa = new test[] {
        new test { a = 'a', x = 1, y = 2, z = 3 },
        new test { a = 'b', x = 2, y = 3, z = 4 }
    };
    string path = System.IO.Directory.GetCurrentDirectory() + "\\go.txt";
    
    using (System.IO.StreamWriter file = new System.IO.StreamWriter(path))
    {
        foreach (test x in aa)
        {
            file.WriteLine("{0} {1} {1} {3}", x.a.ToString(), x.x, x.y, x.z);
        }
    }

}

沒有留言:

張貼留言