static void Main(string[] args) { SaveToDatabase sd = new SaveToDatabase(); //Please note, that although NotifyIfComplete() takes a string parameter, we do not declare it - all we want to do is tell C# where the method is - the details are to come later on. NotifyDelegateWithMessage nofityDelegateWithMessage = new NotifyDelegateWithMessage(NotifyIfComplete); sd.Start(nofityDelegateWithMessage); Console.ReadKey(); }
static void Main(string[] args) { SaveToDatabase sd = new SaveToDatabase(); //Please note, that although NotifyIfComplete() takes a string parameter, we do not declare it - all we want to do is tell C# where the method is so it can be referenced later - we will pass the paramater later. NotifyDelegateWithMessage nofityDelegateWithMessage = new NotifyDelegateWithMessage(NotifyIfComplete); sd.Start(nofityDelegateWithMessage); Console.ReadKey(); }
public void Start(NotifyDelegateWithMessage nd) { //To simulate a saving fail or success, I'm just going to check the current time (well, the seconds) and store the value as variable. string message = string.Empty; if (DateTime.Now.Second > 30) { message = "Saved"; } else { message = "Failed"; } //It is at this point we pass the parameter to our method. nd.Invoke(message); }