Created
March 10, 2017 04:51
-
-
Save iAvinashVarma/0edb6a0e9eb26be7f7af92aa80bac7bb to your computer and use it in GitHub Desktop.
Need of Action Generic Delegate (Real Time Example)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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