控制台中显示的列表

本文关键字:列表 显示 控制台 | 更新日期: 2023-09-27 18:21:49

我正在向列表中添加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());
        }
    }
}

控制台中显示的列表

难道不能只使用linq字符串吗。加入(",",我的列表)?