Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use Tag Message of C #

Shulou Source: shulou.com Published: 2022-06-02 08:40:28 10月03日 Update

This article mainly explains "how to use the Tag Message of C#". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to use Tag Message in C#.

Generally speaking, the Erlang message is a tuple, while the * * elements of the tuple are atoms that identify "what to do". This atom is called the message tag, and this usage is called Tag Message, which is recommended in the Erlang programming specification. In C#, of course, we can also do this:

Tag Message of C #

Class Person: Actor {protected override void Receive (Message message) {if (message.Tag = = "Chat") {Person another = (Person) message.Arguments [0]; Topic topic = (Topic) message.Arguments [1] / /...} else if (message.Tag = = "Eat") {Restaurant restaurant = (Restaurant) message.Arguments [0]; / /...} else if (message.Tag = = "Work") {Person reportTo = (Person) message.Arguments [0] Job job = (Job) message.Arguments [1]; / /...}

The Tag Message diagram of C# is as follows:

Tag Message of C # is the same as Erlang, but due to the lack of pattern matching and automatic binding of Erlang, C # code requires a lot of if. Else judgment, as well as tedious and dangerous transformation operations. In addition, the disadvantages of dynamic types are exactly the same as those of dynamic types in Erlang, both sending and receiving messages are not static types at all, so static checking, editing, or refactoring are difficult. Imagine that if the message structure accepted by a common service changes, all uses of it must be modified correctly-in the absence of static checks, errors can only be found at run time. Erlang has a strong dynamic upgrade capability and can accept continuous online updates. In the .NET platform, if you use this Tag Message approach, it will be more troublesome to fix it when errors are found at run time.

At this point, I believe you have a deeper understanding of "how to use Tag Message in C#". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Tags: Caching message static content dynamic atomic mode type or error learning checking running practical powerful deeper same dangerous difficult tedious Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno Shulou Tech Info Docker NVidia Apple