Все вопросы: [ienumerable]

166 вопросов

похожие теги: ienumerator
3
голосов
2ответов
537 просмотров

How can I reduce IEnumerable<ienumerable>&gt; to IEnumerable<foo>?</foo></ienumerable>

Sorry for the weird caption. What I'm trying to achieve is simple: IEnumerable&lt;IEnumerable&lt;Foo&gt;&gt; listoflist; IEnumerable&lt;Foo&gt; combined = listoflist.CombineStuff(); Example: {{0, 1}, {2, 3}} =&gt; {0, 1, 2, 3} I'm positive there is a Linq expression for this... Sidenote: T...

0
голосов
8ответов
354 просмотров

How to create a enumerator/generator of strings or integers?

I want to have a enumerator/generator that will always provide me with the next value whenever I call say GetNext? Is this possible? Examples: myStringEnumerator.GetNext() -&gt; returns "Identifier01.xml" myStringEnumerator.GetNext() -&gt; returns "Identifier02.xml" myStringEnumerator.GetNe...

0
голосов
2ответов
185 просмотров

Enumerators and Thread-safety

Just to make sure, say that i have this code: this.allObjects = [some linq query]; and have two methods that both read (not modify) this IEnumerable, are they safe to call in parallel? Just looping through a IEnumerable should be safe right?

384
голосов
18ответов
88331 просмотров

Passing a single item as IEnumerable<t></t>

Is there a common way to pass a single item of type T to a method which expects an IEnumerable&lt;T&gt; parameter? Language is C#, framework version 2.0. Currently I am using a helper method (it's .Net 2.0, so I have a whole bunch of casting/projecting helper methods similar to LINQ), but this ...

1
голосов
2ответов
125 просмотров

How to profile an application when deferred execution makes it difficult?

I have this .NET application, which relies on deferred execution. When I am profiling it the methods that consume most time are those who enumerates the IEnumerables. Because of this I think that the methods that must be optimized are not in the Top Time Consuming methods. Did it ever happened ...

1
голосов
3ответов
306 просмотров

Is it possible to get an IEnumerator<t> from a T[]?</t>

Let's say I want to create a collection class that is thread-safe by default. Internally, the class has a protected List&lt;T&gt; property called Values. For starters, it makes sense to have the class implement ICollection&lt;T&gt;. Some of this interface's members are quite easy to implement; ...

24
голосов
1ответов
13275 просмотров

Convert CollectionBase to List or data type usable with Linq

I am using Aspose cells to manipulate Excel spreadsheets. One of the types in the API is a collection of Pictures in the spreadsheet, which derives from CollectionBase: see this link: http://www.aspose.com/documentation/.net-components/aspose.cells-for-.net/aspose.cells.pictures.html I want to ...

3
голосов
1ответов
2349 просмотров

How does Linq use IEnumerable methods after an IOrderedEnumerable method?

In Linq, extension methods like Where return an IEnumerable collection, but sorting methods like OrderBy return an IOrderedEnumerable collection. So, if you have a query that ends with OrderBy (i.e. returns an IOrderedEnumerable), you can't later append a Where method - the compiler complains ab...

0
голосов
1ответов
556 просмотров

Several unusual errors when attempting to convert a string[] to a Dictionary<short string></short>

I have the following code that splits a string on newlines and converts it to a Dictionary for further processing: string[] splitProgram = program.Split(Environment.NewLine.ToCharArray()); short i = 0; Dictionary&lt;short, string&gt; programDictionary = splitProgram.ToDic...

21
голосов
7ответов
5304 просмотров

Caching IEnumerable

public IEnumerable&lt;ModuleData&gt; ListModules() { foreach (XElement m in Source.Descendants("Module")) { yield return new ModuleData(m.Element("ModuleID").Value); } } Initially the above code is great since there is no need to evaluate the entire collection if it is not n...

88
голосов
5ответов
162348 просмотров

How to loop through a collection that supports IEnumerable?

How to loop through a collection that supports IEnumerable?

2
голосов
7ответов
580 просмотров

enumerate through all IEnumerables

I need to send different IEnumerables to an Printer object. This printer object will then do something to them, inside a foreach loop. class Printer { public Printer(IEnumerable list) { foreach (var enumerable in list) { //DO STUFF } } } This let...

1
голосов
4ответов
1916 просмотров

Enumerable.Range implementation

What is the precise implementation of Enumerable.Range in .Net; preferable .Net 4? Is it a yielded for-loop? A custom implementation (IEnumerable, IEnumerator) or?

0
голосов
2ответов
2084 просмотров

"No data exists for the row/column" exception after using ToList

I have an extension method to convert a DbDataReader to an IEnumerable object: public static IEnumerable&lt;IDataRecord&gt; AsEnumerable(this DbDataReader reader) { while (reader.Read()) { yield return reader; } } In my application, I query the database like so: var records = ...

2
голосов
3ответов
923 просмотров

C#: Where to implement a custom IEnumerator<t></t>

Say I have a class that implements IEnumerable&lt;T&gt;. It currently uses the yield keyword in the GetEnumerator() method. But now I need to do a bit more, for example I would like to clean up after myself. To do this, unless I have overlooked anything, I need to implement the IEnumerator&lt;T&g...

11
голосов
3ответов
6797 просмотров

C#: How do you test the IEnumerable.GetEnumerator() method?

Let's say I for example have this class that generates Fibonacci numbers: public class FibonacciSequence : IEnumerable&lt;ulong&gt; { public IEnumerator&lt;ulong&gt; GetEnumerator() { var a = 0UL; var b = 1UL; var c = a + b; while (true) { ...

2
голосов
2ответов
12255 просмотров

C# Silverlight with Entity Framework - Change Return Type On AutoGenerated EntityQuery?

Background Currently I have a C# Silverlight business application which uses RIA Services. The application is hosted in ASP.NET using the ADO.NET Entity Framework and a domain service class to read and write to the SQL Server database. Scenario I have a server-side method in my DomainServiceCl...

10
голосов
5ответов
2039 просмотров

What is the easiest and most compact way to create a IEnumerable<t> or ICollection<t>?</t></t>

So, many times we have a function that accepts an IEnumerable or ICollection as a parameter. In cases where we have single items, but no collection to hold them, we must create a collection before passing them to the function, like: T o1, o2, o3; Foo(new T[] { o1, o2, o3 }); I've always create...

1
голосов
3ответов
1562 просмотров

VB.NET equivalent to this C# linq class

Guys, I'm trying to convert something from C# to VB.NET and I'm having trouble finding an equivlent in VB.NET to C#'s yield keyword. I realize 'yield' is not a convertable keyword to VB.NET, so can someone please show me how I would implement this code in VB.NET. I got all of it converted over ex...

0
голосов
4ответов
2227 просмотров

Does the IEnumerator of .Net IList provide the order of the list?

Can I assume that the IEnumerator I get from an IList (by calling the GetEnumerator method from the IEnumerable interface) will give me the items in the order of the list?

4
голосов
2ответов
20329 просмотров

LINQ-to-List and IEnumerable issues

I am querying an HTML file with LINQ-to-XML. It looks something like this: &lt;html&gt; &lt;body&gt; &lt;div class="Players"&gt; &lt;div class="role"&gt;Goalies&lt;/div&gt; &lt;div class="name"&gt;John Smith&lt;/div&gt; &lt;div class="name"&gt;Shawn Xie&lt;/di...

1
голосов
1ответов
76 просмотров

Enumerable.Unit() function

Finding myself in the situation where I have a method with this signature void DoSomething(IEnumerable&lt;T&gt; before, IEnumerable&lt;T&gt; after) I find myself often having to call it when I've just got one element and not IEnumerable. I thought of adding the three overloads, but that doesn...

2
голосов
6ответов
16804 просмотров

Why can't I foreach through my ViewData or Model?

I keep getting errors trying to iterate through my ViewData in the view there... I even tried strongly typing the view to IEnumerable(App.Models.Namespace) and using Model, to no avail. Either I get an error for lack of a GetEnumerable method or invalid type casting... Any idea how I do this? Mo...

0
голосов
1ответов
272 просмотров

Need Help on Looping Through Deserialized Custom Class

I am having a hard time figuring out how to expose (&amp; loop through) the properties of my Categories class which was serialized (using JSON) in a WCF service and deserialized on the server as illustrated below. JavaScriptSerializer serializer = new JavaScriptSerializer(); Category cat = se...

5
голосов
4ответов
645 просмотров

Are there any pitfalls to using an IEnumerable<t> return type for SQL data?</t>

My question is concerning SQL connection status, load, etc. based on the following code: public IEnumberable&lt;MyType&gt; GetMyTypeObjects() { string cmdTxt = "select * from MyObjectTable"; using(SqlConnection conn = new SqlConnection(connString)) { using(SqlCommand cmd = new SqlComm...

0
голосов
2ответов
2946 просмотров

Update properties of objects in an IEnumerable&lt;&gt;

I am working on some software that should be used for a special type of experiment. The experiments are performed using: 1) A "Chip" (basically an XY grid of known dimensions). 2) Each Chip contains "Electrodes", identified by their X and Y coordinate on the chip and by a unique ID. Each electr...

27
голосов
6ответов
9313 просмотров

Is yield return in C# thread-safe?

I have the following piece of code: private Dictionary&lt;object, object&gt; items = new Dictionary&lt;object, object&gt;; public IEnumerable&lt;object&gt; Keys { get { foreach (object key in items.Keys) { yield return key; } } } Is this thread-s...

6
голосов
4ответов
14526 просмотров

C# IEnumerable<object> to string</object>

For logging purposes, I would like to call the .ToString() method of every object on an object[] array. How can I do this in the simplest way? Say I have : myArray = new Object[]{"astring",1, Customer} Log(????); How can I pass a string such as its value is equal to: "astring".ToStr...

6
голосов
4ответов
3559 просмотров

IEnumerable: Whats does it mean in the context of OOP

Please consider the following code: public class Person ( public string FirstName {get; set;} public string LastName {get; set;} Public int Age {get; set;} } IEnumerable &lt;Person&gt; people; Also i have seen in many programs something like &lt;IQueryable&gt; what does that mea...

1
голосов
4ответов
291 просмотров

Someone please clarify this IEnumerable<t> business for my MVC App?</t>

OK so here we go, one of my classes called Product is implemented like this: namespace DomainModel.Entities { public class Product { public int ProductID { get; set; } public string Name { get; set; } public string Description { get; set; } public decimal ...