I made a comparison with the two forms just to prove it. The first:
IL_0000: ldc.i4.1
IL_0001: stloc.0
IL_0002: ldarg.0
IL_0003: ldloc.0
IL_0004: call instance string C::FindExamByID(int32)
IL_0009: brtrue.s IL_0012
IL_000b: ldarg.0
IL_000c: call instance int32 C::NotFound()
IL_0011: ret
IL_0012: ldc.i4.1
IL_0013: ret
The second:
IL_0000: ldc.i4.1
IL_0001: stloc.0
IL_0002: ldarg.0
IL_0003: ldloc.0
IL_0004: call instance string C::FindExamByID(int32)
IL_0009: brtrue.s IL_0012
IL_000b: ldarg.0
IL_000c: call instance int32 C::NotFound()
IL_0011: ret
IL_0012: ldc.i4.1
IL_0013: ret
Can be checked in Sharplab.
Is the same bytecode so it has no different in processing or memory consumption, in this case. I cannot guarantee that in any case an optimization occurs in a way that is not possible in the other way. Composed of other parts the generated code can be a little different and there is a difference. A simple reordering of instructions can make the processing have another commitment.
The .maxstack 2
equal in both shows that the fact that there is a variable to support the value does not change anything when compared to the slot in the stack frame required for value without variable.