I have a unit test that will test to see if a method that returns the correct IEnumerable. The method builds the IEnumerable using yield return. The class that it is an IEnumerable of is below:
enum TokenType
{
NUMBER,
COMMAND,
ARITHMETIC,
}
internal class Token
{
public TokenType type {get; set;}
public string te...
I was curious to see how the SingleOrFallback method was implemented in MoreLinq and discovered something I hadn't seen before:
public static T SingleOrFallback<T>(this IEnumerable<T> source, Func<T> fallback)
{
source.ThrowIfNull("source");
fallback.ThrowIfNull("fallback");
using (IEnumerator<T> iterator...
Hello,
In the code below,how do I declare myLine as a public(global) variable? The problem is that I can't use the keyword "var".
public static IEnumerable<string> ReadLines(StreamReader reader)
{
while (!reader.EndOfStream)
{
yield return reader.ReadLine();
}
}
private void Filter1(...
Imagine four lists, all at least have this Id string property, but may have other properties:
public class A //or B, C, D
{
public string Id { get; set; }
//..other properties
}
//so:
List<A> a1 = new List<A>();
List<B> a2 = new List<B>();
List<C> a3 = new List<C>();
List<D> a4 = new List<D>();
I want to select all DISTINCT...
I needed a method to give me all but the last item in a sequence. This is my current implementation:
public static IEnumerable<T> SkipLast<T>(this IEnumerable<T> source)
{
using (IEnumerator<T> iterator = source.GetEnumerator())
{
if(iterator.MoveNext())
while(true)
{
...
class String contains very useful method - String.Join(string, string[]).
It creates a string from an array, separating each element of array with a symbol given. But general - it doesn't add a separator after the last element! I uses it for ASP.NET coding for separating with "<br />" or Environment.NewLine.
So I want to add an empty r...
I am trying to accomplish something in C# that I do easily in Java. But having some trouble.
I have an undefined number of arrays of objects of type T.
A implements an interface I.
I need an array of I at the end that is the sum of all values from all the arrays.
Assume no arrays will contain the same values.
This Java code works.
Arra...
I am using some of the LINQ select stuff to create some collections, which return IEnumerable<T>.
In my case I need a List<T>, so I am passing the result to List<T>'s constructor to create one.
I am wondering about the overhead of doing this. The items in my collections are usually in the millions, so I need to consider this.
I assume...
This question is related to a previous question of mine
That's my current code
IEnumerable<Shape> Get()
{
while(//get implementation
yield return new Shape(//...
}
void Insert()
{
var actual = Get();
using (var db = new DataClassesDataContext())
{
db.Shapes.InsertAllOnSubmit(actual);
...
I've got a tree-like structure. Each element in this structure should be able to return a Enumerable of all elements it is root to. Let's call this method IEnumerable<Foo> GetAll(). So if we have
A <-- topmost root
/ \
B C
/ \ / \
D E F G
a call to GetAll on element C returns {C, F, G} (fixed order of eleme...
There's this. Can you do a better job explaining (in small words so I understand :)) why we need a marker interface which doesn't add any methods over IEnumerable?
...
Given....
Public MasterList as IEnumerable(Of MasterItem)
Public Class MasterItem(Of T)
Public SubItems as IEnumerable(Of T)
End Class
I would like a single IEnumerable(Of T) which will iterate through all SubItems of all MasterItems in MasterList
I would like to think that there is a Linq facility to do this, or an extension me...
Hi There,
Is it possible to cast an IEnumerable list to a BindingList collection?
The IEnumerable list is a list of typed objects e.g:
IEnumerable<AccountInfo> accounts = bll.GetAccounts(u.UserName, u.Password);
And my PagingList just extends BindingList:
public class PagingList<T>
{
public BindingList<T> Collection { get; set...
When I'm writing my DAL or other code that returns a set of items, should I always make my return statement:
public IEnumerable<FooBar> GetRecentItems()
or
public IList<FooBar> GetRecentItems()
Currently, in my code I have been trying to use IEnumerable as much as possible but I'm not sure if this is best practice? It seemed righ...
I thought IQueryable<T> was derrived from IEnumerable<T>, so why can't I access the results of my query like a collection of records?
public bool DoLogIn(System.String strUserName, System.String strPassword)
{
if (this.IsLoggedIn)
return false;
ASRDBDataContext ASRData = new ASRDBDataContext();
IQueryable<user> Curr...
I have a list of string values that I want add to a hashtable or other array that can be accessed by key/index but cannot implement it. I have this working how I want but its ugly
List<string> valueList = new List<string>();
valueList.Add("1");
valueList.Add("2");
valueList.Add("3");
Hashtable p ...
[EDIT]
The new Reactive Framework solves the problem outlined below, using the System.Linq.EnumerableEx.MemoizeAll() extension method.
Internally, MemoizeAll() uses a System.Linq.EnumerableEx.MemoizeAllEnumerable<T> (found in the System.Interactive assembly), which is similar to my ThreadSafeCachedEnumerable<T> (sorta).
Here's an awfu...
Imagine that during a
foreach(var item in enumerable)
The enumerable items change. It will affect the current foreach?
Example:
var enumerable = new List<int>();
enumerable.Add(1);
Parallel.ForEach<int>(enumerable, item =>
{
enumerable.Add(item + 1);
});
It will loop forever?
...
I am using extension methods OrderBy and ThenBy to sort my custom collection on multiple fields. This sort does not effect the collection but instead returns and IEnumberable. I am unable to cast the IEnumerable result to my custom collection. Is there anyway to change the order of my collection or convert the IEnumerable result to my...
In the example below, if client code using GetPeople wanted to print the name and age of each person to the console, it would have to use reflection (I suppose) to determine that query contained an IEnumerable(Of Person) and then cast it as such to get at its properties.
Public Function GetPeople() As IEnumerable
Dim query = From p ...