Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public bool TryFoo(string param, out FooThing foo)
- {
- try
- {
- // do whatever
- return true;
- }
- catch
- {
- foo = null;
- return false;
- }
- }
- var dic = new Dictionary<string, string>() { { "Foo", "Bar" } };
- string val = String.Empty;
- string key = null;
- dic.TryGetValue(key, out val); // oops
- private int FindEntry(TKey key)
- {
- if (key == null)
- {
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.key);
- }
- // more stuff
- }
- catch( Exception ex )
- {
- Logger.Log( ex );
- Debug.Assert( false );
- foo = null;
- return false;
- }
- public bool TryGetValue(T key, out U value)
- {
- IList<KeyValue> kvCollection = internalArray[key.GetHashCode() % internalArray.Length];
- for(KeyValue kv in kvCollection)
- {
- if(kv.Key == key)
- {
- value = kv.Value;
- return true;
- }
- }
- value = default(U);
- return false;
- }
- public U GetValue(T key)
- {
- U value;
- if (TryGetValue(key, out value))
- {
- return value;
- }
- throw new KeyNotFoundException(key);
- }
Add Comment
Please, Sign In to add comment