列表显示在控制台中

时间:2015-11-13 08:06:32

标签: c# list console

我在列表中添加了2项,我想在控制台中查看它们。但出了点问题,也许你可以帮忙吗?我认为主要问题在于foreach循环。在哪里说部分找不到。

class Program
{
    static void Main(string[] args)
    {
        public class DocPart
    {
        public string Title { get; set; }
        public string TexLine { get; set; }
    }
​
    public class DocConfig
    {
        public string Description { get; set; }
        public List<DocPart> Parts { get; set; }
        DocConfig()
        {
            var doc = new DocConfig();
            doc.Description = "bla bla";
            doc.Parts.Add(new DocPart { Title = "aaa", TexLine = @"\include{aaa.tex}" });
            doc.Parts.Add(new DocPart { Title = "bbb", TexLine = @"\include{bbb.tex}" });
            this.Parts = new List<DocPart>();
                foreach (DocPart part in doc.Parts)
                       {
                Console.WriteLine(part.Title);
                Console.ReadLine();
            }
        }  
        {
            var serializer = new DataContractJsonSerializer(typeof(DocConfig));
​
            var ms = new MemoryStream(Encoding.UTF8.GetBytes(jsonData));
            var config = (DocConfig)serializer.ReadObject(ms);
​
            return config;
        }
​
        public string SaveToString()
        {
            var serializer = new DataContractJsonSerializer(typeof(DocConfig));
            var ms = new MemoryStream();
            serializer.WriteObject(ms, this);
            return Encoding.UTF8.GetString(ms.ToArray());
        }
    }
}

1 个答案:

答案 0 :(得分:0)

你能不能只使用linq string.Join(“,”,我的名单)?