Created
January 19, 2013 15:13
-
-
Save haldun/4573101 to your computer and use it in GitHub Desktop.
c# delegates
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; | |
class LoginResponse | |
{ | |
public string Token { get; set; } | |
public LoginResponse(string token) { | |
Token = token; | |
} | |
} | |
class LoginService | |
{ | |
public delegate void LoginSuccess(LoginResponse response); | |
public delegate void LoginFailed(string message); | |
public static void Login(string username, string password, LoginSuccess success, LoginFailed failed) | |
{ | |
Console.WriteLine("calling login..."); | |
if (new Random().Next(0, 2) == 0) { | |
success(new LoginResponse("token")); | |
} else { | |
failed("sicis"); | |
} | |
} | |
} | |
class Program | |
{ | |
static void Main() | |
{ | |
Console.WriteLine("hello"); | |
LoginService.Login("username", "password", (loginResponse) => { | |
Console.WriteLine("got token {0}", loginResponse.Token); | |
// user pref => token | |
// user pref => provider | |
// Navigate. ... | |
}, (message) => { | |
Console.WriteLine("sictik {0}", message); | |
// alert ah | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment