TryGetValue
will always return false, because you haven't put anything into the dictionary. After it returns false, the first if block will not run, but the second if block will run, both if blocks will run, because outVal
will have the value of default(DateTime)
.
If, however, the dictionary has some data in it, it's possible for default(DateTime)
to be the value associated with the key you pass to TryGetValue
. In that case, the first if block won't run, but the second if block will run.
EDIT:
The original version of the first paragraph above is incorrect. Notice the negation (!
) in your if statement:
if (!m_unitsWaitingForReadResponse.TryGetValue("teststring", out outVal))
That expression evaluates to true
when TryGetValue returns false
. Therefore, you have the following possibilities, though by your assumption, possibility 3 does not apply in your case:
- The key is not present in the dictionary
- The value associated with the key in the dictionary is not equal to
default(DateTime)
- The value associated with the key in the dictionary is equal to
default(DateTime)
In the first case, TryGetValue returns false; Do Stuff
executes; outVal
is equal to default(DateTime)
; and Do Stuff 2
executes.
In the second case, TryGetValue returns true; Do Stuff
does not execute; outVal
is not equal to default(DateTime)
; and Do Stuff 2
does not execute.
In the third (impossible) case, TryGetValue returns true; Do Stuff
does not execute; outVal
is equal to default(DateTime)
; and Do Stuff 2
executes.