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
private delegate string MyDelegate(string s1, string s2); |
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
public string WhatUp(string firstName, string lastName) | |
{ | |
return $"What's up {firstName} {lastName}"; | |
} |
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
Action<string> logMethods; | |
public void AddLogMethod(Action<string> newLogMethod) | |
{ | |
logMethods += newLogMethod; | |
} | |
public void LogThis(string msg) | |
{ | |
logMethods?.Invoke($"[{DateTime.Now.ToLongDateString()}] {msg}"); |
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
static void ConsoleLog(string s) | |
{ | |
Console.WriteLine($"[CONSOLE] {s}"); | |
} | |
static void Main(string[] args) | |
{ | |
/// section 1 /// | |
Logger log = new Logger(); | |
log.AddLogMethod(ConsoleLog); | |
log.AddLogMethod(delegate (string s) { Console.WriteLine($"[ANON] {s}"); }); |
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
log.LogThis("Hello, delegates"); Thread.Sleep(1000); | |
log.LogThis("Apache started..."); Thread.Sleep(1000); | |
log.LogThis("Mysql started..."); Thread.Sleep(1000); | |
log.LogThis("Exim started..."); Thread.Sleep(1000); | |
log.LogThis("Pureftpd started..."); Thread.Sleep(1000); | |
log.LogThis("Influxdb started..."); Thread.Sleep(1000); | |
log.LogThis("Google started..."); Thread.Sleep(1000); | |
log.LogThis("Git started..."); Thread.Sleep(1000); | |
log.LogThis("Docker started..."); Thread.Sleep(1000); | |
log.LogThis("Apache stopped..."); Thread.Sleep(1000); |
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
List<string> filtered = log.Filter(entry => entry.ToLower().Contains("apache")); // Actually this is LinQ, very cool. I'll talk about this later. | |
foreach(string s in filtered) | |
{ | |
Console.WriteLine(s); | |
} |
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
List<string> entries; | |
public Logger() | |
{ | |
entries = new List<string>(); | |
AddLogMethod(msg => entries.Add(msg)); //or we can use: AddLogMethod(entries.Add); | |
} | |
//Example for Func |
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
public static class [YOUR_CLASS_NAME] | |
{ | |
public static [RETURN_TYPE] [METHOD_NAME](this [TYPE_NAME] s) | |
{ | |
// TODO: Write code here | |
} | |
} | |
/* | |
---[YOUR_CLASS_NAME]---: What ever you like | |
---[RETURN_TYPE]---: What ever you want |
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
public static class HoangExtension | |
{ | |
public static void PlusWithHoang(this string s) | |
{ | |
Console.WriteLine($"{s} - Make from HoangExtension"); | |
} | |
} | |
class Program | |
{ |
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
class Post | |
{ | |
public string status { get; set; } | |
public DateTime timestamp { get; set; } | |
} |
OlderNewer