### Publishing Messages using PubSub.NET in C# Source: https://github.com/jamcar23/pubsub.net/blob/master/README.md Shows how to publish data using `PubSub.Publish`. Any object can publish data. Published data must exactly match the datatype(s), number of arguments, and their order expected by subscribers for them to be invoked. Requires `using PubSubNET;`. ```C# public class MyOtherClass { public void MyOtherMethod() { string str = this.ComputeString(); // some other method to create data PubSub.Publish(str); // will invoke MySubscriber.LogStream PubSub.Publish(str, true); // won't invoke MySubscriber.LogStream because the arguments don't match } } ``` -------------------------------- ### Subscribing with a Method using PubSub.NET in C# Source: https://github.com/jamcar23/pubsub.net/blob/master/README.md Demonstrates subscribing to a string message using a dedicated method. Requires `using PubSubNET;`. The method signature must conform to `System.Action`. The subscriber instance (`this`) and the message type (`string`) are passed to `PubSub.Subscribe`. ```C# public class MySubscriber { public MySubscriber() { PubSub.Subscribe(this, LogString); } private void LogString(string str) { Console.WriteLine(str); } } ``` -------------------------------- ### Subscribing with a Lambda using PubSub.NET in C# Source: https://github.com/jamcar23/pubsub.net/blob/master/README.md Illustrates subscribing to a string message using an inline lambda expression. Requires `using PubSubNET;`. The lambda signature `str => Console.WriteLine(str)` must conform to `System.Action`. The subscriber instance (`this`) and the message type (`string`) are passed to `PubSub.Subscribe`. ```C# public class MySubscriber { public MySubscriber() { PubSub.Subscribe(this, str => Console.WriteLine(str)); } } ``` -------------------------------- ### Unsubscribing from Messages using PubSub.NET in C# Source: https://github.com/jamcar23/pubsub.net/blob/master/README.md Demonstrates how to unsubscribe using `PubSub.Unsubscribe`. Requires the original subscriber instance and the datatype(s) being unsubscribed from. Unsubscribing removes all subscriptions for that specific subscriber instance and the specified datatype combination. Requires `using PubSubNET;`. ```C# public class MySubscriber : IDisposable { public MySubscriber() { PubSub.Subscribe(this, LogString); } private void LogString(string str) { Console.WriteLine(str); } public void Dispose() { PubSub.Unsubscribe(this); } } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.