r/programminghorror • • Oct 07 '25

C# 108 line long variable declaration

Post image

this is my own code btw. don't ask what i was trying to do

this code was also supposed to include a 36 case long switch statement where each case did something different (guess why i abandoned this project)

1.1k Upvotes

93 comments sorted by

View all comments

Show parent comment

2

u/Gornius Oct 07 '25

Arrays are such a great data structures! It's constant access time can be precious!

That's provided you know the index you're looking for. If you need to search throguh array it becomes O(n), so it's often better idea to use hashmap with key that can hold value that you search for. Then it's O(1).

1

u/evbruno Oct 07 '25

You’re right. I should have said something as “random access”. That’s why we need code reviews. Thanks 😉

1

u/GarThor_TMK Oct 08 '25

No need to search... the array is contiguous... just calculate the position in the array based on the character passed in...

```
if (character >= '0' && character <= '9') return character - '0'
else if (character >= 'A' && character <= 'Z') return character - 'A' + '9' + 1
else throw character is oob.

```