猿问

使用逗号分隔的字符串在C#中设置对象

我正在遍历Umbraco节点列表,并使用每个节点上的属性值设置类的属性


foreach (var node in listOfNodeWithProperty)

{

    var faqProperties = new Faq

    {

        Question = node.GetPropertyValue<string>("question"),

        Answer = node.GetPropertyValue<string>("answer"),

        Schemes = node.GetPropertyValue<string>("schemes")

    };


    faqCollection.faqs.Add(faqProperties);


}

我的常见问题课如下


internal class Faq

{

    public string Question { get; set; }

    public string Answer { get; set; }

    public string Schemes { get; set; }

    public IEnumerable<SchemeTypes> SchemeTypes { get; set; } 

}


internal class SchemeTypes

{

    public string SchemeType { get; set; }

}

字符串的所有直接输入,但我要填充SchemeTypes对象的值是逗号分隔的字符串。如何使用此字符串并创建一个数组以填充SchemeTypes?


我想要SchemeTypes作为对象,因为我的最终输出将是JSON


临摹微笑
浏览 180回答 2
2回答
随时随地看视频慕课网APP
我要回答