Answer the question
In order to leave comments, you need to log in
How to get value with foreach and pass it to method?
There is this method:
public string GetPhotoUrl()
{
var posts = Api.Wall.Get(new WallGetParams { Domain = "some_domain", Count = 2 });
foreach (var item in posts.WallPosts)
{
string phUrl = (item.Attachments[0].Instance as Photo).Sizes[0].Url.AbsoluteUri.ToString();
MessageBox.Show(phUrl);
}
return "";
}
Answer the question
In order to leave comments, you need to log in
public IEnumerable<string> GetPhotoUrl() =>
Api
.Wall
.Get(new WallGetParams
{
Domain = "lol.community",
Count = 2
})
.WallPosts
.Select(item => item.Attachments.FirstOfDefault()?.Instance)
.OfType<Photo>()
.Select(item => item.Sizes.FirstOfDefault()?.Url.AbsoluteUrl.ToString());
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question