示例#1
0
        public static void WriteFields()
        {
            Console.WriteLine("Write fields");

            using (var memoryStream = new MemoryStream())
                using (var streamWriter = new StreamWriter(memoryStream))
                    using (var streamReader = new StreamReader(memoryStream))
                        using (var writer = new CsvWriter(streamWriter))
                        {
                            writer.WriteField("String Column");
                            writer.WriteField("Int Column");
                            writer.WriteField("Guid Column");
                            writer.WriteField("Custom Type Column");
                            writer.NextRecord();

                            writer.WriteField("one");
                            writer.WriteField(1);
                            writer.WriteField(Guid.NewGuid());
                            writer.WriteField(new CustomType {
                                First = 1, Second = 2, Third = 3
                            });
                            writer.NextRecord();

                            // done
                            writer.Done();

                            memoryStream.Position = 0;

                            Console.WriteLine(streamReader.ReadToEnd());
                        }
            Console.WriteLine();
        }