I am implementing an IDictionary interface that has an object parameter for its get set .
object this [object key] { get; set; }
I want the key to be a string type, so in my code, I:
(if key.GetType() != typeof(string)) {
I want to make an exception when this happens. However, I do not know which is the most suitable exception to use in this case. The closest I can find is TypeInitializationException and ArgumentException . However, this document states : "Do throw System.ArgumentException or one of its subtypes if bad arguments are passed to the member", which makes me wonder if the right use case is right for me.
What should I use in my case? Should I use Assert instead of throwing an Exception?
source share