Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find an item from an IReadOnlyList<T>?

Tags:

c#

I changed my property type from a List<T> to IReadOnlyList<T>, but I was using the List<T>.Find() method and now the compiler gives error CS1061: 'IReadOnlyList<T>' does not contain a definition for 'Find' and no accessible extension method 'Find' accepting a first argument of type 'IReadOnlyList<T>' could be found (are you missing a using directive or an assembly reference?). How can I find an item from an IReadOnlyList<T>?

like image 232
Hemaolle Avatar asked Oct 24 '25 05:10

Hemaolle


1 Answers

IReadOnlyList<T> implements IEnumerable<T>, you can use IEnumerable<T>.FirstOrDefault() to replace List<T>.Find().

like image 51
Hemaolle Avatar answered Oct 26 '25 18:10

Hemaolle



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!