Hi friends,
i am stuck with converting IEnumerable
IEnumerable
Thanks in advance.
Nitingowda ....
Hi friends,
i am stuck with converting IEnumerable
IEnumerable
Thanks in advance.
Nitingowda ....
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Sam HobbsRank #107 · 20.5K reputationPosted May 27, 2023, 8:24 PM EDT
Are you certain that all items are integers? Where does the IEnumerable
Amit MohantyRank #112 · 20K reputationPosted May 29, 2023, 1:48 AM EDT
Check this:
// Replace with your IEnumerable source IEnumerable enumerable = GetYourIEnumerableObject(); ReadOnlyCollection readOnlyCollection = enumerable.OfType().ToList().AsReadOnly();Prasad RaveendranRank #320 · 7.8K reputationPosted May 29, 2023, 9:51 PM EDT
Hope this would help
using System.Collections.Generic;
using System.Collections.ObjectModel;
IEnumerable enumerable = new List { 1, "two", 3, "four", 5 };
// Step 1: Filter integers from the IEnumerable filteredIntegers = enumerable.OfType();
IEnumerable
// Step 2: Create a ReadOnlyCollection from the filtered integers readOnlyCollection = new ReadOnlyCollection(filteredIntegers.ToList());
ReadOnlyCollection
Please note that any objects in the IEnumerable that are not of type int will be excluded from the resulting ReadOnlyCollection.