Hi,
I'm trying to serialize an object which contains an object which implements IEnumerable<>. The last object also contains an object which implements IEnumerable<>. The objects strucutre is as followed:
[Serializable]
public class A
{
public B _b {get; set; }
}
[Serializable]
public class B : IEnumerable<C>
{
public Lis...
How can I do that?
thats a no go:
ObservableCollection obsCol = new ObservableCollection(myIEnumerable);
scenario:
var query = from c in customers
select new Customer()
{
Products = from p in products
where p.Id = c.Id
...
I can't make any sense of the MSDN documentation for this overload of the Where method that accepts a predicate that has two arguments where the int, supposedly, represents the index of the source element, whatever that means (I thought an enumerable was a sequence and you couldn't see further than the next item, much less do any indexin...
I'm not for sure how the ControlCollection of ASP.Net works, so maybe someone can shed some light on this for me.
I recently discovered the magic that is extension methods and Linq. Well, I was very sad to find that this isn't valid syntax
var c=Controls.Where(x => x.ID=="Some ID").SingleOrDefault();
However from what I can tell, Co...
I've 2 lists of class A, A has implemented Equals(object obj) and GetHashCode() this 2 methods working correctly, code is below.
class A
{
public string TEST
{
get;
set;
}
public override bool Equals(object obj)
{
return ((A)obj).TEST == this.TEST;
}
public override int GetHashCode(...
I need just to clarify that given collection contains an element.
I can do that via collection.Count(foo => foo.Bar == "Bar") > 0) but it will do the unnecessary job - iterate the whole collection while I need to stop on the first occurrence.
But I want to try to use Contains() with a predicate, e.g. foo => foo.Bar == "Bar".
Currentl...
i have used this query to fetch the Record of the Datatable based on the Pagesize.
IEnumerable<DataRow> query1 = from row in dt.AsEnumerable().Take(page_size).Skip(offset) select row;
Datatable boundTable= query1.CopyToDataTable();
first time when it opens the offset will be =0; it gives 10 records,
next time i pass the offset a...
I have the following method that works well, except the yield break statement only breaks out of the current enumerator. I understand why this is the case, but I am drawing a blank over how to propogate the yield break up through the recursive stack.
private static IEnumerable<Node> FindChildrenById(IEnumerable nodes, string parentT...
I need to return an IEnumerable of a dynamically created Dictionary.
pseudo code:
var x = from u in Users
select new dictionary<string, string>{
Add("Name",u.Name),
Add("LastName",u.LastName)
}
I've been trying many ways to get the pseudo code example above but no success...
I would really appreciate your help.
...
How do i go from (cast?, convert?):
IEnumerable<Square>
to
IEnumerable<Shape>
...
I am trying to convert a DataTable to an IEnumerable. Where T is a custom type I created. I know I can do it by creating a List but I was think there was a slicker way to do it using IEnumerable. Here is what I have now.
private IEnumerable<TankReading> ConvertToTankReadings(DataTable dataTable)
{
var tankReadings = n...
I have an IEnumerable that I want to get all the distinct MaterialIDs. I have code that is working but I was wondering if there is a better way possible using LINQ. Here's the code I have:
private IEnumerable<int> GetDistinctMaterialIDs(IEnumerable<TankReading> tankReadings)
{
var distinctMaterialIDs = new List<int>();...
I have method :
public DzieckoAndOpiekunCollection GetChildAndOpiekunByFirstnameLastname(string firstname, string lastname)
{
DataTransfer.ChargeInSchoolEntities db = new DataTransfer.ChargeInSchoolEntities();
DzieckoAndOpiekunCollection result = new DzieckoAndOpiekunCollection();
if (firstname == nul...
I need to prepend a single value to an IEnumerable (in this case, IEnumerable<string[]>). In order to do that, I'm creating a List<T> just to wrap the first value so that I can call Concat:
// get headers and data together
IEnumerable<string[]> headers = new List<string[]> {
GetHeaders()
};
var all = headers.Concat(GetData());
Yuc...
I usually find myself doing something like:
string[] things = arrayReturningMethod();
int index = things.ToList<string>.FindIndex((s) => s.Equals("FOO"));
//do something with index
return things.Distinct(); //which returns an IEnumerable<string>
and I find all this mixup of types/interface a bit confusing and it tickles my potential p...
The method returns IEnumerable via a yield return statement.
If the yield statement never occurs (it's inside conditional logic), will the method return null, or will it return an Enumerable with a count of 0?
...
I just realize that maybe I was mistaken all the time in exposing T[] to my views, instead of IEnumerable<T>.
Usually, for this kind of code:
foreach (var item in items) {}
item should be T[] or IEnumerable<T>?
Than, if I need to get the count of the items, would the Array.Count be faster over the IEnumerable<T>.Count()?
...
Is it possible to create a List or IEnumerable using GetType().
// If T is Type of Contact I want to Return List<Contact>
Test(typeof(Contact));//return List<Type>
public static IEnumerable<T> Test<T>(T t)
{
return new List<T>(); //return List<Type>
}
...
What is the concrete type for this IEnumerable<string>?
private IEnumerable<string> GetIEnumerable()
{
yield return "a";
yield return "a";
yield return "a";
}
...
I'm currently learning F# and I really love the yield! (yield-bang) operator. Not only for its name but also for what it does of course.
The yield! operator basically allows you to yield all elements of a sequence from a sequence expression. This is useful for composing enumerators. Since I regularly encounter big, complicated enumerato...