Finished Using Multi-cast Delegates

building_types
Jason Zhu 2021-02-22 10:37:35 +00:00
parent 3a7ae11abb
commit 4623c69c69
1 changed files with 10 additions and 0 deletions

View File

@ -9,18 +9,28 @@ namespace GradeBook.Tests
public class TypeTests
{
int count = 0;
[Fact]
public void WriteLogDelegateCanPointToMethod()
{
string msg = "test";
WriteLogDelegate log = new WriteLogDelegate(ReturnMessage); // Instantiate a delegate
log += ReturnMessage2; // Multi-cast delegate
var result = log(msg); // Invoking a delegate
Assert.Equal(result, msg);
Assert.Equal(count, 2);
}
string ReturnMessage(string message)
{
count += 1;
return message;
}
string ReturnMessage2(string message)
{
count += 1;
return message;
}