I want to print a percentage value in one (or more) integer intervals. The code below describes object.ProgressChanged
as an EventHandler<EventArgs>
and maxPercent
as a global int
variable.
object.ProgressChanged += (sender, args) => (
if (maxPercent < ((int) args.ProgressPercentage)) {
maxPercent = (int) args.ProgressPercentage;
Console.WriteLine(maxPercent + "%");
}
)
I can easily solve this problem by doing this:
object.ProgressChanged += (sender, args) => aFunction(args);
where aFunction
contains all the same code after the =>
operator in the first piece of code.
I am looking for a more elegant way to approach this problem, if possible, in one line. Any tips?