


This article mainly introduces the calling methods of the C#interface in derived classes and external classes. It analyzes the definition and specific usage of the C# interface in combination with examples. What is needed Friends can refer to
The examples in this article describe the calling methods of C# interfaces in derived classes and external classes. Share it with everyone for your reference, the details are as follows:
The interface of C# is created through the interface keyword, and the interface can contain member variables such as properties and methods. Derived classes of interfaces can implement methods in the interface. A class can inherit multiple interfaces to implement the methods in these interfaces, and an interface can also derive multiple classes. The methods in the interface can be implemented by one or more of these classes. Methods in the interface can be directly called in derived classes of the interface.
Example of calling in a derived class:
//接口 public interface IPersonalService { //接口中的方法 PersonalDTO QueryByUid(int uId); } //接口派生类 public class PersonalService : IPersonalService { //派生类中实现接口方法--隐式实现 public PersonalDTO QueryByUid(int uId) { return _dal.QueryByUid(uId); } //派生类中调用接口方法 public void GetInfo(int userId) { //调用方式一 IPersonalService p = new PersonalService(); PersonalDTO dto = p.QueryByUid(userId); //调用方式二 PersonalService p2 = new PersonalService(); IPersonalService p3 = (IPersonalService)p2; PersonalDTO dto = p3.QueryByUid(userId); } }
When calling a method of an interface in an external class, firstreference thenamespacewhere the interface is locatedand then The steps are the same as calling in the derived class of the interface.
You can also call the interface by declaring an attribute of the interface type after referencing the namespace where the interface is located in the external class, as follows.
public IPersonalService pService{get;set;} public void getInfo() { pService.getInfo(); }
The above is the detailed content of Detailed explanation of C# interface calling method examples in derived classes and external classes. For more information, please follow other related articles on the PHP Chinese website!

C# is widely used in enterprise-level applications, game development, mobile applications and web development. 1) In enterprise-level applications, C# is often used for ASP.NETCore to develop WebAPI. 2) In game development, C# is combined with the Unity engine to realize role control and other functions. 3) C# supports polymorphism and asynchronous programming to improve code flexibility and application performance.

C# and .NET are suitable for web, desktop and mobile development. 1) In web development, ASP.NETCore supports cross-platform development. 2) Desktop development uses WPF and WinForms, which are suitable for different needs. 3) Mobile development realizes cross-platform applications through Xamarin.

The C#.NET ecosystem provides rich frameworks and libraries to help developers build applications efficiently. 1.ASP.NETCore is used to build high-performance web applications, 2.EntityFrameworkCore is used for database operations. By understanding the use and best practices of these tools, developers can improve the quality and performance of their applications.

How to deploy a C# .NET app to Azure or AWS? The answer is to use AzureAppService and AWSElasticBeanstalk. 1. On Azure, automate deployment using AzureAppService and AzurePipelines. 2. On AWS, use Amazon ElasticBeanstalk and AWSLambda to implement deployment and serverless compute.

The combination of C# and .NET provides developers with a powerful programming environment. 1) C# supports polymorphism and asynchronous programming, 2) .NET provides cross-platform capabilities and concurrent processing mechanisms, which makes them widely used in desktop, web and mobile application development.

.NETFramework is a software framework, and C# is a programming language. 1..NETFramework provides libraries and services, supporting desktop, web and mobile application development. 2.C# is designed for .NETFramework and supports modern programming functions. 3..NETFramework manages code execution through CLR, and the C# code is compiled into IL and runs by CLR. 4. Use .NETFramework to quickly develop applications, and C# provides advanced functions such as LINQ. 5. Common errors include type conversion and asynchronous programming deadlocks. VisualStudio tools are required for debugging.

C# is a modern, object-oriented programming language developed by Microsoft, and .NET is a development framework provided by Microsoft. C# combines the performance of C and the simplicity of Java, and is suitable for building various applications. The .NET framework supports multiple languages, provides garbage collection mechanisms, and simplifies memory management.

C# and .NET runtime work closely together to empower developers to efficient, powerful and cross-platform development capabilities. 1) C# is a type-safe and object-oriented programming language designed to integrate seamlessly with the .NET framework. 2) The .NET runtime manages the execution of C# code, provides garbage collection, type safety and other services, and ensures efficient and cross-platform operation.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Dreamweaver Mac version
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool
