0

I'm on about my third day of C# programming and ran into a confusing issue. I'm attempting to get the biggest index utilized in a 2D Array of booleans. So given:

booleans = new bool[x,y];
booleans[0,0] = false
booleans[0,1] = false
booleans[1,0] = false
booleans[1,1] = false
booleans[2,3] = false

I'm attempting to find that the largest x value is 2 and the largest y value is 3.

Thanks for your time!

Bob
  • 1,344
  • 3
  • 29
  • 63
  • [Array.GetLength(Int32) Method](https://learn.microsoft.com/en-us/dotnet/api/system.array.getlength?redirectedfrom=MSDN&view=net-7.0#System_Array_GetLength_System_Int32_) gives the dimensions. The largest index in that - 1. – 001 Jan 24 '23 at 21:11
  • @JohnnyMopp Using array.getlength simply gives me the length of the entire array and not the biggest x and y values – Bob Jan 24 '23 at 21:15
  • @Bob - No, the `GetLength(n)` method will return the size of any dimension. Are you using the `Length` property instead? That _does_ return the total number of elements. – D Stanley Jan 24 '23 at 21:17
  • 1
    Or, are you trying to find the biggest indexes where a value was _set_? Meaning if the array was initialized to a size of 10,10 but you only set through 2,3 you want 2 and 3? If so then you need to use a nullable type as an array of booleans will have all "false" values whether you explicitly set them or not. – D Stanley Jan 24 '23 at 21:18
  • GetLength worked... so far I am much preferring Python.. if you could make it an answer I'll accept – Bob Jan 24 '23 at 21:34

0 Answers0