score:1
assuming that you have to have an 11-dimensional array (doing some m-theory work?) and that no other data structure is possible, and given that you don't want to use looping to find the maximum value in the array, that leaves you with just one possibility that i can think of:
create a new managedarray class with two private fields, one for values and one for maximums.
create an indexer with 11 index parameters. the get is as simple as anything with 11 parameters can be:
public int this[int index1, int index2, int index3, int index4, int index5, int index6, int index7, int index8, int index9, int index10, int index11]
{
get
{
return (int) values.getvalue( index1, index2, index3, index4, index5, index6, index7, index8, index9, index10, index11 );
}
the set will call setvalue and then update the current maximums with the new value if the new value is bigger than the existing maximum for that set of dimensions.
create a maximum property that takes a bunch of index values, have it return the current value of maximums at those index values.
now change arr1 and arr2 to be instances of the managedarray class.
what we've done is to trade a loop at request time (when you want to know the maximum) with a slightly more time-consuming array setter that tracks maximum values so we can look them up in constant time whenever requested.
afaik, that's the only way you can do it.
note that you can make it a lot easier to read by using the params
keyword, but then the setter will be a little more complicated when you're updating the maximums. up to you.
score:0
i know this will not really help you, but you can not use linq in this case, because multidimensional arrays are not implementing the ienumerable interface.
so do not waste your time to solve your problem with linq :)
score:0
how can you not iterate over all elements when you need to calculate the maximum value?
imo it would make your life easier if you placed your data in a more accessible data structure, at least something supporting ienumerable<t>
.
Source: stackoverflow.com
Related Query
- List or Array of String Contain specific word in Html Source Code
- LINQ Source Code Available
- .NET 4 Code Contracts: "requires unproven: source != null"
- Maximum number of occurrences a character appears in an array of strings
- Explanation of Code : retrieve item from Array using FirstorDefault()
- C# Array Maximum
- creating Linq to sqlite dbml from DbLinq source code
- source code for LINQ 101 samples
- Linq code to get the index of an object in an array from an object within a list
- how to simplify code to print all items in an array use one line code in c#
- c# Linq or code to extract groups from a single list of source data
- CSV values in an array from a custom source
- How to use LINQ to select object with minimum or maximum property value
- How to perform .Max() on a property of all objects in a collection and return the object with maximum value
- Convert string[] to int[] in one line of code using LINQ
- Code equivalent to the 'let' keyword in chained LINQ extension method calls
- Value cannot be null. Parameter name: source
- Check whether an array is a subset of another
- Get all elements but the first from an array
- Convert a list of objects to an array of one of the object's properties
- printing all contents of array in C#
- Get all column names of a DataTable into string array using (LINQ/Predicate)
- Find index of a value in an array
- Linq code to select one item
- C# - code to order by a property using the property name as a string
- How do I find the text within a div in the source of a web page using C#
- Roslyn failed to compile code
- Convert string to int array using LINQ
- Conversion from List<T> to array T[]
- LINQ to find array indexes of a value
More Query from same tag
- Dynamic Link, changing a property for every item in a list
- Linq and EF on .Any()
- Get groups of 4 elements from name value list using LINQ in C#
- LinkQ Exception
- Create Delete/Edit buttons for muliple records from linq using hidden value?
- Flatten and group complex objects in Linq and preserve null children
- LINQ: Combine 2 groups
- Select new with an if statement inside
- Getting wrong output with linq join query
- Sort One Array from Another array order?
- How to convert Expression<Func<T, object>> to Expression<Func<object, object>>
- Entity Framework pulling null in three tables
- Linq query throws exception while foreach query works
- Find items from a list which exist in another list
- LINQ query becomes invalid upon editing result data?
- Find index of a key? Dictionary .NET
- how to reach a class's property in LINQ
- Convert method to async
- Sort and filter IQueryable in datagridview
- WCF Operation Contract - Best way to get the result sorted by any column
- EF Core. How to extract (left) joined table as collection?
- c# linq question
- How to form a Method based syntax in Linq Entity Framework
- LINQ pivot on a single field
- How to parameterize a boolean expression in Linq?
- How to return a path of nodes from a recursive hierarchy given a condition?
- how to set string variable as property in subquery
- LINQ lambda expression throws Sequence contains no elements
- How do I write this in Linq to reduce code?
- Adding a calculated field in LINQ select results?