score:11
Accepted answer
how about:
return _tabs.oftype<editortabviewmodel>().any(t => t.cansave);
here:
oftype<>
is a non-buffering filter that restricts us toeditortabviewmodel
any
is short-circuiting, so returns true as soon as a match is found
score:1
using the linq extensions you could write something like
_tabs.any( p => p is editortabviewmodel && ((editortabviewmodel)t).cansave)
score:1
try something like:
return _tabs.firstordefault(y => y is editortabviewmodel && ((editorviewmodel)t).cansave) != null;
score:2
yes, you can improve. something like this would probably work:
return _tabs.any(x => x is editortabviewmodel && ((editortabviewmodel)x).cansave);
Source: stackoverflow.com
Related Query
- LINQ Source Code Available
- Trying to optimize linq query
- C#/LINQ: Trying to optimize performance
- Trying to understand LINQ code using c#
- C# - Linq optimize code with List and Where clause
- creating Linq to sqlite dbml from DbLinq source code
- source code for LINQ 101 samples
- c# Linq or code to extract groups from a single list of source data
- To optimize my linq query which listed as top consuming query in azure query performance insight tool
- Getting InvalidCastException when trying to implement sorting in Entity Framework Code First using Linq
- Optimize Linq code
- Improve performance in linq query - trying to change the query from subquery to join
- Suggestions on how to optimize code for ordering by string in linq
- Convert string[] to int[] in one line of code using LINQ
- Code equivalent to the 'let' keyword in chained LINQ extension method calls
- Linq code to select one item
- LINQ performance FAQ
- How are people unit testing code that uses Linq to SQL
- Performance of LINQ Any vs FirstOrDefault != null
- foreach + break vs linq FirstOrDefault performance difference
- For vs. Linq - Performance vs. Future
- What is the Efficiency and Performance of LINQ and Lambda Expression in .Net?
- LINQ performance Count vs Where and Count
- Aggregate vs Sum Performance in LINQ
- Is multiple .Where() statements in LINQ a performance issue?
- Linq ToList/ToArray/ToDictionary performance
- SQL vs LINQ performance
- LINQ Performance for Large Collections
- LINQ Lambda vs Query Syntax Performance
- LINQ query to perform a projection, skipping or wrapping exceptions where source throws on IEnumerable.GetNext()
More Query from same tag
- How can I set custom property of an Entity type in LINQ to Entities query and still return a IQueryable<T>?
- How to use LINQ to add two fields in a class that is in the List?
- c# - query nested type with LINQ
- Changing Entity connection string error
- Linq Combine Left Join Data
- The LINQ expression node type 'Invoke' is not supported in LINQ to Entities with skip
- ASP.NET MVC Displaying a user's roles as comma separated string
- How to delete rows of two different table having same id mvc
- c# join two int lists where values are the same and values are at same index
- List<classObject> group by on the objects in C#
- Best way to use same object for adding records LINQ C#
- Ordering lists within a list in C#
- Why do LINQ operations lose the static type of the collection?
- The method ‘Skip’ is only supported for sorted input in LINQ to Entities. The method ‘OrderBy’ must be called before the method ‘Skip’
- Generic List Find using lambda expression in c#
- How to construct a Where clause for an EntitySet
- access an array element inside a LINQ to Entities set
- Linq-to-SQL Retrieving child tables throws InvalidCastException
- DataReader to Linq'd query of Dictionary(String, Object)
- LINQ to SQL Failing to Insert to the Database
- How to check for the duplicates in an ObservableCollection?
- How can I test if a string can be converted to a decimal in Linq?
- LINQ/LAMBDA filter query by date
- Get index of object in a list using Linq
- Determine if a sequence contains all elements of another sequence using Linq
- Search for an Array or List in a List
- Using Linq to XML, how can I select the elements that have exactly x number of parent elements?
- Building a Sensor Monitoring System using RX
- How to get IEnumerable filled with ErrorMessages from ModelState in ASP.NET Core with LINQ
- linq and string array