Finished Using Multi-cast Delegates
parent
3a7ae11abb
commit
4623c69c69
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue