如果将在.NET中完成应用程序是什么? -哪些应用程序将使用此概念 [英] What are the applications, if this would be done in .NET. - Which applications will use this concept

查看:63
本文介绍了如果将在.NET中完成应用程序是什么? -哪些应用程序将使用此概念的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
我只是给出一个基本概念,请深入思考.
让我马上开始,
假设以下类,

Hi Guys,
I am just giving a basic concept, think it in deep.
Let me proceed right away,
Let''s assume the following classes,

public class A
{
    public string PropA { get; set; }
    public void MethodOfA()
    {
        Console.WriteLine("Calling MethodOfA from A");
    }
    public void MethodOfB()
    {
        Console.WriteLine("Calling MethodOfB from A");
    }
}
public class B
{
    public string PropA { get; set; }
    public string PropB { get; set; }
    public void MethodOfA()
    {
        Console.WriteLine("Calling MethodOfA from B");
    }
}


public class C : A, B
{
}


C类是从A和B类派生的
现在,类A和B都包含一个通用方法MethodOfA()所以,当我说


Class C is derived from A and B classes
Now, class A and B both contains a common method MethodOfA() So, when I say

C c = new C();
c.MethodOfA();



它先从A调用MethodOfA(),然后从B依次调用MethodOfA.输出将是
从A调用MethodOfA
从B调用MethodOfA
现在,当我说



It calls MethodOfA() from A and then it calls MethodOfA from B sequentially.And the output will be
Calling MethodOfA from A
Calling MethodOfA from B
Now, when I say

C c = new C();
c.A.MethodOfA();


它仅调用A的方法,并且与B类相同.
输出将是
从A调用MethodOfA
因此,我可以连续调用一次方法,也可以按类名调用它.
同样,我们也可以申请属性.
我们可以一键设置属性,也可以一键获取属性.
我们可以通过类名设置属性,也可以通过类名获取属性.


It calls method of A only and same for B class.
And the output will be
Calling MethodOfA from A
So, I can call method in a row at one shot or I can call it by class name.
Same thing we can apply for the properties too.
We can set properties at one shot or we can get property at one shot.
We can set property by a class name or we can get property by a class name.

推荐答案

您提出的第一个问题是双重继承.您只能继承一个类,所有其他继承都必须是接口.

并且如果您需要一个比其他类调用方法的类,则可以考虑使用Fascade模式来实现.
Well the first issue in what you are proposing is the dual inheritance. You can only inherit a single class and all other inheritances must be interfaces.

And if you need a class calling the method of another class than what you need to do is consider the Fascade Pattern for implementing that.


您的类C不能从两个父类继承- C#仅支持< bold>单一继承...类C只能继承一个类:A或B,不能同时继承.接口的另一件事:
类可以实现多个接口
your class C cannot inherit from both parent classes - C# supports only <bold>single inheritance... class C can inherit just from one class: A or B, not both. Another thing with interfaces:
class can implement multiple interfaces


这篇关于如果将在.NET中完成应用程序是什么? -哪些应用程序将使用此概念的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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