C# How to make a list out of IEnumerable





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















I'm currently playing with TvDbSharper (https://github.com/HristoKolev/TvDbSharper) and i have a question about IEnumerable.
What i'm trying to do is get all the Id for a given series and then add the result in a listView.



This code gives me the first Id in the list:



const int SeriesId = 78804;
var tasks = new List<Task<TvDbResponse<BasicEpisode>>>();
var firstResponse = await client.Series.GetEpisodesAsync(SeriesId, 1);
for (int i = 2; i <= firstResponse.Links.Last; i++)
{
tasks.Add(client.Series.GetEpisodesAsync(SeriesId, i));
}
var results = await Task.WhenAll(tasks);
var episodes = firstResponse.Data.Concat(results.SelectMany(x => x.Data));

epsListview.View = View.Details;
epsListview.Columns.Add("Episode", 100);
string arr = new string[4];
ListViewItem itm;
arr[0] = episodes.First().Id.ToString();
itm = new ListViewItem(arr);
epsListview.Items.Add(itm);


but what i want is to make a new line in the epsListview for each id available.



I never used IEnumerable and i'm still very novice using c#, i've been stuck with this problem for over a week now. can anyone help me with this ?



Thanks!!










share|improve this question


















  • 2





    Maybe I'm misunderstanding the question, but .ToList() will convert an IEnumerable into a List.

    – Gabriel Luci
    Nov 17 '18 at 3:25






  • 1





    Do you know how to use a foreach statement?

    – BJ Myers
    Nov 17 '18 at 6:35


















0















I'm currently playing with TvDbSharper (https://github.com/HristoKolev/TvDbSharper) and i have a question about IEnumerable.
What i'm trying to do is get all the Id for a given series and then add the result in a listView.



This code gives me the first Id in the list:



const int SeriesId = 78804;
var tasks = new List<Task<TvDbResponse<BasicEpisode>>>();
var firstResponse = await client.Series.GetEpisodesAsync(SeriesId, 1);
for (int i = 2; i <= firstResponse.Links.Last; i++)
{
tasks.Add(client.Series.GetEpisodesAsync(SeriesId, i));
}
var results = await Task.WhenAll(tasks);
var episodes = firstResponse.Data.Concat(results.SelectMany(x => x.Data));

epsListview.View = View.Details;
epsListview.Columns.Add("Episode", 100);
string arr = new string[4];
ListViewItem itm;
arr[0] = episodes.First().Id.ToString();
itm = new ListViewItem(arr);
epsListview.Items.Add(itm);


but what i want is to make a new line in the epsListview for each id available.



I never used IEnumerable and i'm still very novice using c#, i've been stuck with this problem for over a week now. can anyone help me with this ?



Thanks!!










share|improve this question


















  • 2





    Maybe I'm misunderstanding the question, but .ToList() will convert an IEnumerable into a List.

    – Gabriel Luci
    Nov 17 '18 at 3:25






  • 1





    Do you know how to use a foreach statement?

    – BJ Myers
    Nov 17 '18 at 6:35














0












0








0








I'm currently playing with TvDbSharper (https://github.com/HristoKolev/TvDbSharper) and i have a question about IEnumerable.
What i'm trying to do is get all the Id for a given series and then add the result in a listView.



This code gives me the first Id in the list:



const int SeriesId = 78804;
var tasks = new List<Task<TvDbResponse<BasicEpisode>>>();
var firstResponse = await client.Series.GetEpisodesAsync(SeriesId, 1);
for (int i = 2; i <= firstResponse.Links.Last; i++)
{
tasks.Add(client.Series.GetEpisodesAsync(SeriesId, i));
}
var results = await Task.WhenAll(tasks);
var episodes = firstResponse.Data.Concat(results.SelectMany(x => x.Data));

epsListview.View = View.Details;
epsListview.Columns.Add("Episode", 100);
string arr = new string[4];
ListViewItem itm;
arr[0] = episodes.First().Id.ToString();
itm = new ListViewItem(arr);
epsListview.Items.Add(itm);


but what i want is to make a new line in the epsListview for each id available.



I never used IEnumerable and i'm still very novice using c#, i've been stuck with this problem for over a week now. can anyone help me with this ?



Thanks!!










share|improve this question














I'm currently playing with TvDbSharper (https://github.com/HristoKolev/TvDbSharper) and i have a question about IEnumerable.
What i'm trying to do is get all the Id for a given series and then add the result in a listView.



This code gives me the first Id in the list:



const int SeriesId = 78804;
var tasks = new List<Task<TvDbResponse<BasicEpisode>>>();
var firstResponse = await client.Series.GetEpisodesAsync(SeriesId, 1);
for (int i = 2; i <= firstResponse.Links.Last; i++)
{
tasks.Add(client.Series.GetEpisodesAsync(SeriesId, i));
}
var results = await Task.WhenAll(tasks);
var episodes = firstResponse.Data.Concat(results.SelectMany(x => x.Data));

epsListview.View = View.Details;
epsListview.Columns.Add("Episode", 100);
string arr = new string[4];
ListViewItem itm;
arr[0] = episodes.First().Id.ToString();
itm = new ListViewItem(arr);
epsListview.Items.Add(itm);


but what i want is to make a new line in the epsListview for each id available.



I never used IEnumerable and i'm still very novice using c#, i've been stuck with this problem for over a week now. can anyone help me with this ?



Thanks!!







c# list ienumerable






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 17 '18 at 3:17









Jeremy GoyetteJeremy Goyette

71




71








  • 2





    Maybe I'm misunderstanding the question, but .ToList() will convert an IEnumerable into a List.

    – Gabriel Luci
    Nov 17 '18 at 3:25






  • 1





    Do you know how to use a foreach statement?

    – BJ Myers
    Nov 17 '18 at 6:35














  • 2





    Maybe I'm misunderstanding the question, but .ToList() will convert an IEnumerable into a List.

    – Gabriel Luci
    Nov 17 '18 at 3:25






  • 1





    Do you know how to use a foreach statement?

    – BJ Myers
    Nov 17 '18 at 6:35








2




2





Maybe I'm misunderstanding the question, but .ToList() will convert an IEnumerable into a List.

– Gabriel Luci
Nov 17 '18 at 3:25





Maybe I'm misunderstanding the question, but .ToList() will convert an IEnumerable into a List.

– Gabriel Luci
Nov 17 '18 at 3:25




1




1





Do you know how to use a foreach statement?

– BJ Myers
Nov 17 '18 at 6:35





Do you know how to use a foreach statement?

– BJ Myers
Nov 17 '18 at 6:35












1 Answer
1






active

oldest

votes


















1














It looks like you're wanting to build an array of IDs from an IEnumerable of episodes, and add that array to a single ListViewItem. This should do that.



string arr = episodes.Select(episode => episode.Id.ToString()).ToArray()
ListViewItem itm = new ListViewItem(arr);
epsListview.Items.Add(itm);





share|improve this answer
























  • Exactly what i needed! I just learned something new ! Thanks alot !!!! :)

    – Jeremy Goyette
    Nov 19 '18 at 0:58











  • You're welcome. LINQ extension methods are very useful for working with IEnumerables.

    – bcwhims
    Nov 19 '18 at 22:12












Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53347867%2fc-sharp-how-to-make-a-list-out-of-ienumerable%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














It looks like you're wanting to build an array of IDs from an IEnumerable of episodes, and add that array to a single ListViewItem. This should do that.



string arr = episodes.Select(episode => episode.Id.ToString()).ToArray()
ListViewItem itm = new ListViewItem(arr);
epsListview.Items.Add(itm);





share|improve this answer
























  • Exactly what i needed! I just learned something new ! Thanks alot !!!! :)

    – Jeremy Goyette
    Nov 19 '18 at 0:58











  • You're welcome. LINQ extension methods are very useful for working with IEnumerables.

    – bcwhims
    Nov 19 '18 at 22:12
















1














It looks like you're wanting to build an array of IDs from an IEnumerable of episodes, and add that array to a single ListViewItem. This should do that.



string arr = episodes.Select(episode => episode.Id.ToString()).ToArray()
ListViewItem itm = new ListViewItem(arr);
epsListview.Items.Add(itm);





share|improve this answer
























  • Exactly what i needed! I just learned something new ! Thanks alot !!!! :)

    – Jeremy Goyette
    Nov 19 '18 at 0:58











  • You're welcome. LINQ extension methods are very useful for working with IEnumerables.

    – bcwhims
    Nov 19 '18 at 22:12














1












1








1







It looks like you're wanting to build an array of IDs from an IEnumerable of episodes, and add that array to a single ListViewItem. This should do that.



string arr = episodes.Select(episode => episode.Id.ToString()).ToArray()
ListViewItem itm = new ListViewItem(arr);
epsListview.Items.Add(itm);





share|improve this answer













It looks like you're wanting to build an array of IDs from an IEnumerable of episodes, and add that array to a single ListViewItem. This should do that.



string arr = episodes.Select(episode => episode.Id.ToString()).ToArray()
ListViewItem itm = new ListViewItem(arr);
epsListview.Items.Add(itm);






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 17 '18 at 7:51









bcwhimsbcwhims

822511




822511













  • Exactly what i needed! I just learned something new ! Thanks alot !!!! :)

    – Jeremy Goyette
    Nov 19 '18 at 0:58











  • You're welcome. LINQ extension methods are very useful for working with IEnumerables.

    – bcwhims
    Nov 19 '18 at 22:12



















  • Exactly what i needed! I just learned something new ! Thanks alot !!!! :)

    – Jeremy Goyette
    Nov 19 '18 at 0:58











  • You're welcome. LINQ extension methods are very useful for working with IEnumerables.

    – bcwhims
    Nov 19 '18 at 22:12

















Exactly what i needed! I just learned something new ! Thanks alot !!!! :)

– Jeremy Goyette
Nov 19 '18 at 0:58





Exactly what i needed! I just learned something new ! Thanks alot !!!! :)

– Jeremy Goyette
Nov 19 '18 at 0:58













You're welcome. LINQ extension methods are very useful for working with IEnumerables.

– bcwhims
Nov 19 '18 at 22:12





You're welcome. LINQ extension methods are very useful for working with IEnumerables.

– bcwhims
Nov 19 '18 at 22:12




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53347867%2fc-sharp-how-to-make-a-list-out-of-ienumerable%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Xamarin.iOS Cant Deploy on Iphone

Glorious Revolution

Dulmage-Mendelsohn matrix decomposition in Python