score:2
Accepted answer
pure linq:
var arr = new byte[] { 1, 2, 3, 4, 5, 6 };
var res = arr.zip(arr.skip(1), (a, b) => new { a, b }).select((x, i) => new { x, i })
.firstordefault(v => v.x.a == 3 && v.x.b == 4);
if (res != null)
{
console.writeline(res.i);
}
score:1
given how you said you want to search for bytes in a list, i'm assuming you have an object of list<byte>
, named list
, and a byte[]
, named bytes
.
list<byte> list = new list<byte>();
byte[] bytes = { 0x01, 0x02 };
list.where((b, i) => (list.count() >= i + 1 ? false : (b == bytes[0] && list[i + 1] == bytes[1]))).first();
the ternary expression ensures you don't have an arrayoutofboundsexception
Source: stackoverflow.com
Related Query
- Search for combination of two items with Linq
- Search two lists for at least one match with LINQ
- Saved projection expression for re-use in different linq expressions with two source objects
- Get different and common items in two arrays with LINQ
- Using LINQ to search a byte array for all subarrays that start/stop with certain byte
- LINQ for comparing two lists with complex entities
- linq - how do you do a query for items in one query source that are not in another one?
- Get duplicates for two columns with LINQ
- Is possible to run a query with linq to search for a period of time?
- Search for entire name based on three columns with LINQ
- Stubbing Code for Test With Linq Expressions and Lambdas
- Linq Filtering items with ForEach crashes for large data set
- Select distinct items by combination of two columns and where Value of third column is max- LINQ
- Compare items in two lists and replace foreach loop with LINQ
- Linq wild card search with Sql Functions.Pat Index for multiple columns
- Filter list with linq for similar items
- linq SQL statements for joining two id with single list
- Open source LINQ search engine for website
- Using LINQ to search two lists for match and return boolean for every item
- How to merge two lists while adding metadata indicating value source with LINQ statement?
- Linq to EF Search for a string that does not start with a Letter
- source code for LINQ 101 samples
- Easiest way of comparing two lists in C# with LINQ and adding missing items to Entity Class
- C# LINQ code for two list compare and replace
- How to query two tables for matching values with linq and C#?
- Search for whole word with Linq to SQL
- How to match two Lists with only items that are different in Linq
- LINQ Query to search for users with partial name
- JSON - LINQ Query for object or an array to group two data with same key value pair
- How to search for number in string with method Contains and Linq in c#?
More Query from same tag
- When querying a collection using linq it always returns a null
- C# Convert SQL query with Case statement to LINQ
- Setting properties of object
- How to deal with parallel arrays in LINQ?
- Implement Smart Search with Entity framework
- Double group into Dictionary<int, Dictionary<string, List<Model>>>()
- Calculate average of an specific data that can be neutral
- c# and Linq query to object[,]
- Using ASP.Net, what would be the best control to use in this situation?
- How to append my list elements
- jtable-jquery sorting and linq to sql
- EF Core 3.1 Intermediate Projection VS Iterating Result to Set Additional Property
- c# Linq to entities .The specified type member 'CityName' is not supported in LINQ to Entities
- C# re-use LINQ expression for different properties with same type
- Rewriting a Linq statement
- LINQ aggregating multiple IEnumerables into one?
- Month and Year drop down list for ASP.NET mvc
- Linq query for sorting by date, then by status, then by name
- Gridview ObjectDataSource InvalidOperationException when Deleting
- Linq to XML: parse some elements and skip some elements
- Round double in LINQ to Entities
- SQL to LINQ with JOIN and SubQuery
- Updating many records via "Linq to entities" and not "Linq to objects"
- Split string to hash table using LINQ
- System.UnauthorizedAccessException C# in winforms
- Linq query with .Contains not returning any records
- C# retrieve multiple XML attributes from specific elements for manipulation
- Passing Data on Navigation
- How can I use Linq to include a List<myDto> in selectTableDto?
- How to change linq to include href of a table cell when scraping a Table using htmlagilitypack