Following is the sample code, and am looking to send new values dynamically every time in the select new statement below, Trying to add new object dynamically in the select new statement below, currently am passing hard coded values but how can I send dynamic values and keep adding to existing values?
public static void Main(string[] args)
{
// Post p = new Post();
List<Post> posts = Program.GetPosts();
// foreach(posting in posts)
JObject o = JObject.FromObject(new
{
channel = new
{
title = "James Newton-King",
link = "http://james.newtonking.com",
description = "James Newton-King's blog.",
item =
from p in posts
orderby p.title
select new //here
{
title = p.title,
description = p.description,
link = p.link,
category = p.Item
}
}
});
Console.WriteLine(o);
}
public static List<Post> GetPosts()
{
Post c = new Post();
List<Post> ch = new List<Post>();
c.title = "hello title";
c.link = "link";
c.description = "des";
c.Item = "Item";
ch.Add(c);
Post p = new Post();
c.title = "hello title1";
c.link = "link1";
c.description = "des1";
c.Item = "Item1";
ch.Add(p);
return ch;
}
}
class Channel
{
public string title;
public string link;
public string description;
public string Item;
public string name;
}