Alternative to IndexOutOfRangeException

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Magnus.Moraberg@gmail.com

    Alternative to IndexOutOfRangeException

    Hi,

    I have the following methods -

    public MyClass this[int index]
    public MyClass this[string myClassName]

    if this[int index] recieves an index which is outside the bounds of
    the concerned array, I throw - IndexOutOfRange Exception

    What exception should I throw if no object in the concerned array has
    the name myClassName, for this[string myClassName]?

    Thanks,

    Barry.
  • Mick Wilson

    #2
    Re: Alternative to IndexOutOfRange Exception

    On Jun 25, 9:16 am, Magnus.Morab... @gmail.com wrote:
    What exception should I throw if no object in the concerned array has
    the name myClassName, for this[string myClassName]?
    If you're using the string myClassName as a key to your collection,
    you can use the KeyNotFoundExce ption.

    The exception that is thrown when the key specified for accessing an element in a collection does not match any key in the collection.

    Comment

    Working...