Using input parameter with Enum value
Hi
Given the following code example
// Method declaration
private bool ValidRequest(RequestBase request, ResponseBase response, Validate validate)
// Condition statement
if ((Validate.ClientTag & validate) == Validate.ClientTag)
Validate is an Enum with a variable ClientTag that has a value of 0x0001 assigned.
Am I right in saying that given Validate.ClientTag is an Enum, the assignment operator cannot be used to Set the input parameter validate. As a result the & operator needs to be used instead?
In addition the expression (Validate.ClientTag & validate) has to be encapsulated into its own parenthesis within the if statement due to the mismatch of types ClientTag and bool?
Thanks
Answers (4)
1 Well, the Dispose() method only cleans up unmanaged resources such as file handles, database connections etc. It doesn't remove the managed object (x) itself from memory.
The garbage collector (GC) does that when there are no longer any references to the object at a time of its choosing.
Generally speaking, the GC does a good job and you should not try to interfere with its operation. Apart from calling Dispose() if the object implements IDisposable, the only thing you should do is to set object references to null if they are no longer needed and they aren't about to go out of scope anyway as this might enable the GC to clean up the object more quickly.
However, you can force a collection to take place with the static GC.Collect() method and, if you're about to perform a critical operation where you cannot afford the GC kicking in in the middle of it, then you can call this method first.
Accepted 0 Thanks for the thorough explanation!