In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-20 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
Editor to share with you how to use the interface interface in C#, I believe most people do not know much about it, so share this article for your reference, I hope you will learn a lot after reading this article, let's learn about it!
The contact with the C # interface interface is not long, which at first feels very simple. Interface is added to the C # program, which will save a lot of manpower and material resources in the later expansion and maintenance of the program. The previous implementation can use the newly built Class:Project to constrain and invoke the interface as a whole. However, there are some restrictions when it comes to the instantiation of a class and the invocation of its properties and methods. The newly created Program in this example cannot instantiate the properties of clsVBProgramer and clsCSharpProgramer. After testing, it is found that the WriteProgram of class Project cannot output the properties of the first two.
The source code for the implementation of the C# interface API is as follows:
Using System; namespace Delegate {class DelegateSample {static void Main (string [] args) {clsProject Proj = new clsProject (); IProgrammer Program; / / call VBProgrammer Program = new clsVBProgramer (); Proj.WriteProgram (Program); / / call CSharpProgrammer Program = new clsCSharpProgramer (); Proj.WriteProgram (Program);}} / define interface interface IProgrammer {void WriteCode ();} / define VBProgrammer class class clsVBProgramer:IProgrammer {string StrVB = "VBProbramer" Public void WriteCode () {Console.WriteLine ("calling class {0}", StrVB);}} / define CSarpProgrammer class class clsCSharpProgramer: IProgrammer {string StrCS = "CsharpProgramer"; public void WriteCode () {Console.WriteLine ("calling class {0}", StrCS);}} / / define Project class for class clsProject {public void WriteProgram (IProgrammer Programmer) {Programmer.WriteCode () } these are all the contents of the article "how to use the interface Interface in C#". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
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.