Chris Hammond Chris Hammond - 1 year ago 111
C# Question

Inline assignment on IF statement

Is it possible to "short-circuit" assignment and validation into an IF statement..

Something line this..

if ((Match m = Regex.Match(data, pattern)).Success)

Answer Source

Assignment yes, declaration no:

Match m;
if ((m = Regex.Match(data, pattern)).Success)

Declaration expressions in C# have been suggested but have not been implemented yet.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download