Skip to content

Instantly share code, notes, and snippets.

@iAvinashVarma
Created March 10, 2017 04:51
Show Gist options
  • Select an option

  • Save iAvinashVarma/0edb6a0e9eb26be7f7af92aa80bac7bb to your computer and use it in GitHub Desktop.

Select an option

Save iAvinashVarma/0edb6a0e9eb26be7f7af92aa80bac7bb to your computer and use it in GitHub Desktop.
Need of Action Generic Delegate (Real Time Example)
using System;
using System.Threading;
namespace NeedOfActionDelegate
{
class Program
{
static void Main(string[] args)
{
MachineUpdate machineUpdate = new MachineUpdate();
machineUpdate.ApplyUpdates();
Console.ReadLine();
}
}
class MachineUpdate
{
Action<double> updateProgress = value => Console.WriteLine("{0}% is completed.", Math.Round(value, 2));
public void ApplyUpdates()
{
var bulletins = new string[] { "MS17-005", "MS17-004", "MS17-003", "MS17-002", "MS17-001", "MS16-155", "MS16-154", "MS16-153", "MS16-152", "MS16-151", "MS16-150", "MS16-149", "MS16-148", "MS16-147", "MS16-146", "MS16-145", "MS16-144", "MS16-142", "MS16-141", "MS16-140", "MS16-139", "MS16-138", "MS16-137" };
int totalBulletins = bulletins.Length;
for (int currentBulletinIndex = 1; currentBulletinIndex <= totalBulletins; currentBulletinIndex++)
{
var progressValue = Convert.ToDouble((1.0 * currentBulletinIndex) / totalBulletins);
ApplyUpdate(bulletins[currentBulletinIndex - 1]);
updateProgress(progressValue * 100);
}
}
public void ApplyUpdate(string currentBulletin)
{
Console.WriteLine("Applying {0}.", currentBulletin);
Thread.Sleep(1000);
Console.WriteLine("Applied {0}.", currentBulletin);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment