Last active
May 16, 2017 07:05
-
-
Save mshwf/2ada799267bc8aaa945b99c0368c593d to your computer and use it in GitHub Desktop.
Implementing SuccessCallBack and FailedCallBack
This file contains 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.Collections.Generic; | |
namespace TestConsole | |
{ | |
public class Book | |
{ | |
public int Id { get; set; } | |
public string Title { get; set; } | |
} | |
public delegate void SuccessCallBack(string title, string message); | |
public delegate void FailedCallBack(string message); | |
class Program | |
{ | |
public static List<Book> books = new List<Book>(); | |
static void Main(string[] args) | |
{ | |
var book = new Book { Id = 3, Title = "My Book" }; | |
AddBook(book, Success, Failed); | |
} | |
static void AddBook(Book book, SuccessCallBack SuccessCB, FailedCallBack FailedCB) | |
{ | |
books.Add(book); | |
bool bSuccess = true; | |
//bool bSuccess = false; | |
if (bSuccess) | |
{ | |
SuccessCB(book.Title, "Added successully"); | |
} | |
if (!bSuccess) | |
{ | |
FailedCB("Failed to add!!"); | |
} | |
} | |
private static void Failed(string message) | |
{ | |
Console.WriteLine(message); | |
} | |
private static void Success(string title, string message) | |
{ | |
Console.WriteLine(title + " " + message); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment