Skip to content

Instantly share code, notes, and snippets.

@mshwf
Last active May 16, 2017 07:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mshwf/2ada799267bc8aaa945b99c0368c593d to your computer and use it in GitHub Desktop.
Save mshwf/2ada799267bc8aaa945b99c0368c593d to your computer and use it in GitHub Desktop.
Implementing SuccessCallBack and FailedCallBack
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