C#中的接口 [英] Interface in C#

查看:50
本文介绍了C#中的接口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好!


这是我在学校的考试,我不知道如何修复它。


我应该将C#中我的程序的方法存储到一个额外的类中。所有课程都将一起处理,所以我需要做一个名为"操作"的界面。使用名为"执行"的方法。 


我的方法目前在一个类中一起调用:


- " Text_Speichern"'
- " Zeichen_Zaehlen"

- " Zeilen_Zaehlen"

- " Ersetzen_Clear"


我很高兴回复!如果您需要了解有关我的项目的更多详细信息,请告诉我们!


解决方案

您好,


由于您是新来的,我们倾向于通过将他们指向正确的方向,但不提供代码示例,因为你什么都不知道,这就是为什么我推荐以下,一个已经完成的代码示例。


https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/interface


这是上面帮助的页面上的第一个例子。

 interface ISampleInterface 
{
void SampleMethod();
}

类ImplementationClass:ISampleInterface
{
//显式接口成员实现:
void ISampleInterface.SampleMethod()
{
//方法实现。
}

static void Main()
{
//声明一个接口实例。
ISampleInterface obj = new ImplementationClass();

//致电会员。
obj.SampleMethod();
}
}


Hello everyone!

This is my exam in school and i dont know how to fix it.

I should store the Methods of my Programm in C# to an extra class. All classes will be process together so i need to do an Interface called "operation" with an Method which called"execute". 

My Methods at the moment in one class together called:

- "Text_Speichern"'
- "Zeichen_Zaehlen"
- "Zeilen_Zaehlen"
- "Ersetzen_Clear"

Im very glad about any Reply! If you have to know more details about my project, please let me know! 

解决方案

Hello,

Since you are new here we tend to assist with students by pointing them in the proper direction but not to provide code samples as you learn nothing from that which is why I recommend the following, a already done code sample.

https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/interface

This is the first example on the page above which help.

interface ISampleInterface
{
    void SampleMethod();
}

class ImplementationClass : ISampleInterface
{
    // Explicit interface member implementation: 
    void ISampleInterface.SampleMethod()
    {
        // Method implementation.
    }

    static void Main()
    {
        // Declare an interface instance.
        ISampleInterface obj = new ImplementationClass();

        // Call the member.
        obj.SampleMethod();
    }
}


这篇关于C#中的接口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆