Chris Hammond Chris Hammond - 11 months ago 87
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.