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 Articles
- 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
- Add node and childnodes to XML File
- Not supported exception with TruncateTime entity framework function
- LINQ Keyword search with orderby relevance based on count (LINQ to SQL)
- Using AddRange with Distinct() is not working with Enum
- LINQ-to-entities - Null reference
- Linq query to d3.js chart
- Could not find an implementation of the query pattern for source type
- Create and initialize dictionary from list
- Clean way to Compare / Copy between Similar Classes
- How to Quickly Remove Items From a List
- How do I create subsets of one list from one condition in c#
- How to get a complement list of objects using linq and EntityFramework
- Groupby and Compare the results in Linq
- LINQ Contains() with list of string
- IEnumerable<List<T>> to List<T>
- Grabbing most recent transaction/record
- Get all records from db from a specific datetime
- Linq to SQL check if data exists and Update/Insert depending
- How to return duplicate values from an array?
- How to update list using linq in c#