سؤال

A R# inspection of my solution told me "'Local variable 'fs' is never used'" about this line:

var fs = new FormatString();

Okay, then; just get rid of the whole shebang, right?

Instead, R#'s action was to remove just the var declaration and assignment, leaving:

new FormatString();

To my chaprise (chagrined surprise), it compiles!

But does it make any kind of sense?

هل كانت مفيدة؟

المحلول

Theoretically, yes. An object is constructed; the constructor executes. It might well do something "interesting" in the process.

نصائح أخرى

If there are side effects in the constructor, then it's important for it to run. If it is side effect free, then you can remove the whole thing.

public FormatString()
{
    LaunchTheNukes();
}

in this case, yes it's doing 'something'.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top