IEnumerable is empty?
I know it probably doesnt matter/affect performance for the most part but I hate the idea of getting an IEnumerable and doing .Count(). Is there a IsEmpty or NotEmpty or some function? (similar to stl empty()) ...
I know it probably doesnt matter/affect performance for the most part but I hate the idea of getting an IEnumerable and doing .Count(). Is there a IsEmpty or NotEmpty or some function? (similar to stl empty()) ...
Hi There is the enumerable extension method Take<TSource>( IEnumerable<TSource> source, int count ) which takes the first count elements from the start. Is there a way to take the elements from the end? or even better a way to take the elements from an offset to the end? Thanks ...
I've seen plenty of examples (NerdDinner, Sanderson's Sports Store, etc.) where a view is bound to a collection of objects. The syntax in the view is usually something like this... <%@ Page... Inherits="System.Web.Mvc.ViewPage<IEnumerable<MyViewModel>>" %> ... <% foreach (var myViewModel in Model) { %> I've also seen plenty of exampl...
Should be easy... class Base{} class Foo:Base{} public bool Bar(Type t){ // return ??? // NB: shouldn't know anything about Foo, just Base } Assert.True(Bar(typeof(IEnumerable<Foo>)); Assert.False(Bar(typeof(IEnumerable<Base>)); Assert.False(Bar(typeof(string)); Assert.False(Bar(typeof(Foo)); Just to answer question why 2n...
I'm using IEnumerable orderby to sort my items in ascending format but it does not work my query is like this: IEnumerable<Step> steps = allsteps.Where(step => step.X <= Y); steps = steps.OrderBy(step => step.X); its not deffer to use OrderBy or OrderByDescending why? I'm want to use Sum() method to sum some items and item orders i...
Hello, first i must assume that i'm not very familiar with the C# yield keyword and its function. What is the best/easiest way to "translate" it into VB.NET? Especially i tried to convert this code into VB.NET, but i failed with: yield return new MatchNode(++index, current.Value); What i have is: Imports System.Collections Imports ...
Possible Duplicate: LINQ Partition List into Lists of 8 members. I've got an IEnumerable<T> and I'd like to transform it into an IEnumerable<List<T>> where each List is a batch of items in the same order as the original enumerator. Each batch should be batchSize items in length, except for the last batch which should contain l...
I've got a bunch of classes that can Process() objects, and return their own objects: public override IEnumerable<T> Process(IEnumerable<T> incoming) { ... } I want to write a processor class that can wrap one of these processors, and log any uncaught exceptions that the wrapped Process() method might throw. My first idea was somethi...
Hi everyone, I'm in the process of learning Interfaces. I've been reading through some books/articles and so far so good - I've written a few sample Interfaces of my own. Yay :) Now, I've noticed that one of the most popular C# Interfaces around is the IEnumerable Interface. It's used quite a lot for all sorts of collections etc.. Any...
I have an type that is implementing IEnumerable<T> interface, all is ok: open System type Bar() = interface Collections.IEnumerable with member x.GetEnumerator () = null interface Collections.Generic.IEnumerable<int> with member x.GetEnumerator () = null But things goes wrong if type inherits IEnumerable...
open System type Foo() = interface Collections.IEnumerable with member x.GetEnumerator () = null type Bar() = interface Collections.IEnumerable with member x.GetEnumerator () = null interface Collections.Generic.IEnumerable<int> with member x.GetEnumerator () = null let xs, ys = Foo(), Bar() ...
Simple example - you have a method or a property that returns an IEnumerable and the caller is iterating over that in a foreach() loop. Should you always be using 'yield return' in your IEnumerable method? Is there ever a reason not to? While I understand that it may not always be necessary to, or even "better" (maybe it's a very smal...
I have a generic class that implements IList public class ListBase<T>: IList<T>, IListBase{ IEnumerator<T> GetEnumerator(){ .... System.Collections.IEnumerator GetEnumerator(){ return GetEnumerator();} } The IListBase is an interface I use to access methods on this class for cases where I don't know the type of T at runtime. ...
I always thought that enough requirement that class should satisfy to be able to use Where() with it is to implement IEnumerable. But today a friend of mine asked me a question, why he cannot apply Where() to the object of SPUserCollection class (it is from Sharepoint). Since this class is derived from SPBaseCollection which implements ...
I am trying to split a collection into multiple collections while maintaining a sort I have on the collection. I have tried using the following extension method, but it breaks them incorrectly. Basically, if I was to look at the items in the collection, the order should be the same when compared to the broken up collections joined. He...
If I have the following how to do I cast the result of the lambda expression back to the Customer type from IEnumerable without having to iterate over it. public class Customer : CustomerModel { public List<Customer> CustomerList {get;set;} public Customer GetCustomerFromListById(long id) { retur...
ResourceSet rs = Resources.Loading.ResourceManager.GetResourceSet(CultureInfo.CurrentCulture, true, true); so far I have that line, which gets me all the loading messages, my problem is the ResourceSet is an IEnumerable. I can't figure out what the best way to return a random string in this enumerable would be. Ideally I'd do somethi...
Hi All Im trying to get an enumberable collection from a dictionary held array. Or should I say, I'm trying to write an extension method for my dictionary objects which store arrays to return an IEnumerable item when the result is null. Im using dictionarys to store array datasets (there are speed reasons for this), which I extract at ...
We have a DAL that we're using with NHibernate.Search, so classes that need to be indexed are decorated with an attribute Indexed(Index:="ClassName"), and each property that needs to be be indexed has an attribute Field(Index:=Index.Tokenized, Store:=Store.No) . When one wants the index to drill down special objects, there's the attribut...
I'm digging in in my Microsoft Visual Studio Documentation and I found this article under C# Reference (ms-help://MS.VSCC.v90/MS.MSDNQTR.v90.en/dv_csref/html/df01e266-5781-4aaa-80c4-67cf28ea093f.htm), It's about Interface Interface. Here's the example code: class SelectSample1 { static void Main() { //Crea...