Skip to content

Instantly share code, notes, and snippets.

@anelson
Created August 31, 2010 09:34
Show Gist options
  • Save anelson/558789 to your computer and use it in GitHub Desktop.
Save anelson/558789 to your computer and use it in GitHub Desktop.
Delegates vs Events, Kyiv 2010
public class UserManager {
//This class allows other code to perform username/password validation. Which is the better way to do this?
public class AuthenticateUserEventArgs : EventArgs {
public string UserName { get; set; }
public string Password { get; set; }
}
// This is one way
public event EventHandler<AuthenticateUserEventArgs> AuthenticateUser;
// This is another way
public Func<string, string, bool> AuthenticatedUser { get; set; }
}
public class UserManager {
// This class notifies other code when a user logs on. Which is the better way to do this?
// This is one way
public event EventHandler UserLoggedOn;
// This is another way
public Action UserLoggedOn { get; set; }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment