Dictionary class has TryGetValue
List I guess has only Contains (doesn’t work based on indexes)
But this is not enough for how I do this..
when I add some kind of object to List.
I use list.IndexOf(objectJustAdded); to get index location of object.
In my server a client has same list and just sends the index of list to server thats how server accesses the object stored on list.
Now I’m trying to prevent ArgumentOutOfRangeException which I don’t think can happen, but I want to make server stable against hacker attack if someone sends malformed packet with bad index to list.. this exception may pop out.
What is best way to handle it? Try/Catch? anything better?
If you’re going to loop through the indexes, you could do something like this: