In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "how to achieve C# Multicast". The content of the explanation is simple and clear, and it is easy to learn and understand. let's follow the editor's train of thought to study and learn "how to achieve C# Multicast".
One agent delegates several methods at the same time. As we said earlier, if you want to build a house, you have to build not only houses, but also gardens and other buildings. But they are all building houses, and the parameters passed are the same and the return values are of the same type. So why don't we find an agent to accomplish such a task? Leaving these things to him alone can not save us a lot of time and money. Yeah, we can do that, System. MulticastDelegate you can actually find this class in. Net framework, which is translated into C # Multicast on MSDN. In fact, it also overloads the operator + =. In fact, there is little difference between C# Multicast and single-channel proxy in terms of usage. You can look at the following example.
Using System
Namespace Multi_castDelegate
{
/ / /
/ Summary description for Class1.
/ / /
Class MyClassDelegate
{
/ / /
/ The main entry point for the application.
/ / /
Public delegate string IntDelegate (string s)
}
}
Using System
Namespace Multi_castDelegate
{
/ / /
/ Summary description for MyImplementingClass.
/ / /
Public class MyClass
{
Public MyClass ()
{
}
Public static string WriteString (string s)
{
Console.WriteLine ("Writing string")
Return "null"
}
Public static string logString (string s)
{
Console.WriteLine ("loging string")
Return "null"
}
Public static string TransmitString (string s)
{
Console.WriteLine ("Transmitting string")
Return "null"
}
}
}
The Main class:
Using System
Using System.Threading
Namespace Multi_castDelegate
{
/ / /
/ Summary description for Test.
/ / /
Public class Test
{
Public static void Main ()
{
MyClassDelegate.StringDelegate
Writer,Logger,Transmitter
MyClassDelegate.StringDelegate
MyDelegate
Writer=new
MyClassDelegate.StringDelegate (MyClass.WriteString)
/ calling Writer
Writer ("hello i am Writer just acting like Single cast")
Logger=new MyClassDelegate.StringDelegate (MyClass.logString)
/ calling Logger
Logger ("hello i am Logger just acting like Single-cast")
Transmitter=new MyClassDelegate.StringDelegate (MyClass.TransmitString)
/ calling Transmitter
Transmitter ("hello i am Transmitter just acting like Single-cast")
/ here mydelegate used the Combine method of System.MulticastDelegate
/ and the delegates combine
MyDelegate= (MyClassDelegate.StringDelegate) System.Delegate.
Combine (Writer,Logger)
MyDelegate ("used Combine")
/ here Transmitter is also added using the overloaded form of Combine
MyDelegate+=Transmitter
MyDelegate ("Using Overloaded Form")
/ now using the Remove method
MyDelegate= (MyClassDelegate.StringDelegate) System.Delegate.
Remove (myDelegate,Writer)
MyDelegate ("Without Writer")
/ overloaded Remove
MyDelegate-=Transmitter
MyDelegate ("Without Transmitter")
System.Threading.Thread.Sleep (2300)
}
}
}
The focus of the face example is to look at the two operators that have been overloaded. "- =" and "+ =". From the above example, you can clearly see how C# multicast proxies more than one method at a time. Of course, you can also delete the ones you don't want and use the "- =" operator.
Thank you for your reading. the above is the content of "how to achieve C# Multicast". After the study of this article, I believe you have a deeper understanding of how to realize C# Multicast. The specific use of the situation also needs to be verified by practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.