Hi,
I was wondering why the GetEnumerator() method was factored out of IEnumerator and placed in IEnumerable. It seems to me that it would make more sense to keep all of the enumerator methods in IEnumerator.
Thanks,
Scott
...
If a method takes a parameter of type System.Collections.IList can I legitimately/safely pass a value of type System.Collections.Generic.IEnumerable<T>?
I would appreciate a thorough explanation of why this is possible and what actually happens to the object T when the IEnumerable<T> is used inside of the method.
Is it converted to t...
Not sure how to call it, but say you have a class that looks like this:
class Person
{
public string Name;
public IEnumerable<Person> Friends;
}
You then have a person and you want to "unroll" this structure recursively so you end up with a single list of all people without duplicates.
How would you do this? I have already ma...
One of the extension methods on IEnumerable<T> is .AsEnumerable(). This method converts the enumerable object it was called on into an instance of IEnumerable<T>. However, since an object must implement IEnumerable<T> in order to apply to this extension method, converting to IEnumerable<T> is a simple matter of casting to IEnumerable<T>....
I have an interesting need for an extension method on the IEumerable interface - the same thing as List.ConvertAll. This has been covered before here and I found one solution here. What I don't like about that solution is he builds a List to hold the converted objects and then returns it. I suspect LINQ wasn't available when he wrote his...
I've got some data in a view that I would like to pass to a child partial view. Part of that data is a list of dates that I would like to display in the partial view. I'm pretty sure I can't pass an IEnumerable from one view to another (when I try list is null in the controller). Assuming that is the case, is there a good work around?
I...
Hi everyone,
I have a method with returns an IEnumerable<T> and I'm trying to debug the code inside that method.
Each time I step through the code in Visual Studio during debug, it steps over the method in question.
When I place a breakpoint inside the method it never gets hit. The code is definately running as I've tested by yield re...
I'm still learning some of this c# stuff, and I couldn't find an answer to this question. Assuming that I have a list of MyObject implementing MyInterface
public class MyObject : IMyInterface { ...}
public List<MyObject> MyObjectList;
How can I return an IEnumerable<IMyInterface> with the contents of MyObjectList?
I mean, right now...
Hi everyone,
I have an IEnumerable<T> method that I'm using to find controls in a WebForms page.
The method is recursive and I'm having some problems returning the type I want when the yield return is returnig the value of the recursive call.
My code looks as follows:
public static IEnumerable<Control>
...
I have a testing scenario where I want to check if two collections are equal. I have found the class Microsoft.VisualStudio.QualityTools.UnitTesting.CollectionAssert, but it only works on ICollection<T>. Since I'm testing a repository for Entity Framework, and thus need to compare IObjectSet<T>s, that won't do - IObjectSet<T> doesn't imp...
A method returns a sequence, IEnumerable<T>, and you now want to check if it is empty. How do you recommend doing that? I'm looking for both good readability and good performance.
The first and most obvious way is to check that the count is greater than zero:
if(sequence.Count() == 0)
Has decent readability, but terrible performance...
Hello.
This is the code:
IEnumerable<table> results = db_dane.ExecuteQuery<table>(query);
table - is a database table,
query - sql query (example: select * from table),
db_dane - linq datacontext.
How to convert results of this query to xml or dataset?
...
possible duplicate:
Cannot serialize parameter of type ‘System.Linq.Enumerable… ’ when using WCF, LINQ, JSON
Hi,
If my method signiature looks like this, it works fine.
[WebGet]
MyClass[] WebMethod()
If the signiature looks like this
[WebGet]
IEnumerable<T> WebMethod()
I get the following error:
Cannot serialize parameter...
According to MSDN there is an overload for the ObservableCollection constructor to which you can pass an IEnumerable. According to the very short MSDN page this will make a "Copy" of the Ienumerable.
How do I determine how this will behave? Will the "Copy" be totally independent of the original or will changes made to the Ienumerable (S...
Why cant I use an IEnumerable with params? Will this change in the future?
...
I currently use the following base collection.
abstract class BaseCollection : Collection<BaseRecord>
{
}
I would like to replace it with the generic collection below. This however is not a trivial task due to the amount of derived classes that currently implement BaseCollection.
abstract class BaseCollection<TRecord...
I have next very non-optimized code:
void Summarize(IEnumerable<Section> sections)
{
this.DateBegin = sections.Select(s => s.Date).Min();
this.DateEnd = sections.Select(s => s.Date).Max();
this.Income = sections.Where(s => s.IsIncome).Sum(r => r.Amount);
this.ExpenditureBank = sections.Where(s => s.IsExpenditureBank).Sum...
I have a class which retrieves the data from DB.
[Table(Name = "Ilanlar")]
public class Ilan
{
[Column(Name="ilan_id" ,IsPrimaryKey = true)]
public int M_ilan_id;
[Column(Name="refVerenUser_id")]
public int M_refVerenUser_id;
}
And i am binding the data comes from db via the class above.
private void ItemsGet()
...
Can anyone explain how on earth the following statement can generate
System.InvalidOperationException: The value null not be assigned a member of type System.Boolean since it is a value type that cannot have the value null (freely translated from Swedish (see also)).
if (user.Friends.Count() == 0)
user is a User and Friends is a...
From what I can see, the ForEach method is available only for the List class.
Why is that? I can see no reason for ForEach not to be available to any class implementing the IEnumerable/IEnumerator interfaces, and this is a really useful method if you need to perform a small action (1 line is more readable than 1 line + 2 boilerplate fo...