score:2
that's because derivedenumerator
implements both ienumerable<basethingy>
and ienumerable<derivedthingy>
(indirectly via ireadonlycolleciton
). so when you do
var y = derivedenumerator.where(s => s.gethashcode() == s.gethashcode());
compiler cannot figure out what is the type of s
in lamdba. is that derivedthingy
? is that basethingy
? both are possible. so you need to tell it explicitly what that is:
var y = derivedenumerator.where<derivedthingy>(s => s.gethashcode() == s.gethashcode());
or
var y = derivedenumerator.where((derivedthingy s) => s.gethashcode() == s.gethashcode());
that said, it's quite unusual design and you might reconsider it. how exactly depends on what you are trying to do (so, why do you need to inherit enumerators this way).
score:0
ambiguity issue
namespace classlibrary1
{
public class basethingy { }
public class derivedthingy : basethingy { }
public class baseenumerator : ireadonlycollection<basethingy>
{
public int count => throw new notimplementedexception();
public ienumerator<basethingy> getenumerator()
{
throw new notimplementedexception();
}
ienumerator ienumerable.getenumerator()
{
throw new notimplementedexception();
}
}
public class derivedenumerator : baseenumerator, ireadonlycollection<derivedthingy>
{
ienumerator<derivedthingy> ienumerable<derivedthingy>.getenumerator()
{
throw new notimplementedexception();
}
}
public class application
{
public void main()
{
baseenumerator baseenumerator = new baseenumerator();
derivedenumerator derivedenumerator = new derivedenumerator();
// works...
var x = baseenumerator.where(s => s.gethashcode() == s.gethashcode());
// works now
var y = derivedenumerator.where<derivedthingy>(s => s.gethashcode() == s.gethashcode());
}
}
}
Source: stackoverflow.com
Related Query
- C#: Using LINQ on a derived iterator class when both the derived class and its base implement IEnumerable
- How can I check the number of calls to the database in LINQ query when using .NET Core and Code First?
- What are the difference between .Select, .Any, and .Count when using LINQ
- Is a full list returned first and then filtered when using linq to sql to filter data from a database or just the filtered list?
- When using the Linq methods .Any(<predicate>) and .All(<predicate>) on an IList, are the predicates applied to the list in a strict sequence?
- How to get the distinct record name and its each record count to bind to gridview in C# using Linq from SQL Server
- Can I receive both the return value and resultset from a procedure using Linq to sql?
- Why did I get an exception "Cannot implicitly convert type 'bool' to 'long?'" when using the LINQ Sum method and how to fix it?
- C# LINQ query fails when using IsAbstract property during derived class scan with reflection?
- How to create nested object graphs using Linq when the objects are immutable and reference their parent
- Querying the database using EF Code First and Linq
- Is there anyway anonymous joins using linq may be performed when one of the datatypes is nullable and the other isn't?
- Linq query throws entity or complex type cannot be constructed in a linq to entity, even when i remove the class name just using select new { ..}
- How can I filter a dictionary using LINQ and return it to a dictionary from the same type
- Why does C# compiler create private DisplayClass when using LINQ method Any() and how can I avoid it?
- Differences between IEquatable<T>, IEqualityComparer<T>, and overriding .Equals() when using LINQ on a custom object collection?
- Using LINQ to take the top 100 and bottom 100?
- Take the first five elements and the last five elements from an array by one query using LINQ
- When using LINQ, what is the difference between && and multiple where clauses?
- EF Query using .Contains() and .ToLowerInvariant() Results in no matches when match is found at the end of a string
- Some data is missing in the Export to Excel using DataTable and Linq
- Obtaining the min and max of a two-dimensional array using LINQ
- Using LINQ to do some calculations on the current and the next object
- Enumerable.Empty<T>().AsQueryable(); This method supports the LINQ to Entities infrastructure and is not intended to be used directly from your code
- Sort a list and all its nested objects using LINQ
- Access all of the data after joining two tables and group them using linq
- When using "yield" why does compiler-generated type implement both IEnumerable and IEnumerator
- Add quotes at the beginning and end of each element in list using LINQ
- LINQ to SQL - Compile error when extending data context with partial class and methods
- LINQ isn't calling Dispose on my IEnumerator when using Union and Select, expected behavior or bug?
More Query from same tag
- How to properly create a union from two tables selecting only specifc columns where one column is going to empty with some text
- Create an iQueryable which is case insensitive for unit testing linq to entities - NSubstitute
- Group By With Complex Selector
- How to Invoke this linq query?
- handling no result found
- how to convert int to string in Linq to entities
- C# Dynamic LINQ: Select with Sum on dictionary indexer
- Creating Panel with images and linkbutton at runtime
- How can I group parts of a class partition key with LINQ?
- LINQ Entities Where clause not in correct place
- ViewData Int32 must be of type IEnumerable in MVC
- Exception when changing data source to SQL
- How to add list data to multi sub class list data?
- c# linq csv change delimiter of last element
- Possible to return linked object with Stored Procedure
- Conditional LINQ query on self-joining table with 2 sets of data
- how to retrieve data from many to many relationship in mvc c# with linq
- How can I perform a LINQ Query and select?
- How can I find the most items of a certain type in a List?
- Search In claims
- Combine contents of two files using LINQ to CSV
- Change loops on 2D List to LINQ
- Argument types do not match Transforming anonymous Expression<Func<T,U>> to non anonymous Expression<Func<T,U>>
- Group by single column in Linq c#
- How to get the amount of colums from a SQL database with LinqDataSource?
- Transform a DataTable with a single column to a Dictionary where the index is the key
- How to use LINQ to perform a simultaneous search of all child items
- Filter a generic list based on a reflected value of its entries with linq
- Linq - conditional Contains()
- How can I get my ajax request date format to match my database date format?