Working with Excel and VSTO, I always work with multidimensional arrays. For a multidimensional array, such as Array.Find (), there are no built-in functions.
You basically have two options: create your own helper methods and implement a common search pattern there, or create a list of domain objects corresponding to the contents of a multidimensional array. I personally had a tendency to choose the last option.
If you decide to write a helper method, it might look something like this (something like this):
// you could easily modify this code to handle 3D arrays, etc. public static class ArrayHelper { public static object FindInDimensions(this object[,] target, object searchTerm) { object result = null; var rowLowerLimit = target.GetLowerBound(0); var rowUpperLimit = target.GetUpperBound(0); var colLowerLimit = target.GetLowerBound(1); var colUpperLimit = target.GetUpperBound(1); for (int row = rowLowerLimit; row < rowUpperLimit; row++) { for (int col = colLowerLimit; col < colUpperLimit; col++) { // you could do the search here... } } return result; } }
You are referring to a static extension like this in other parts of your application code:
object[,] myArray = GetMyArray();
source share