静态类,接口和抽象类的目的是什么? [英] What is the purpose of static class, interface and abstract class?

查看:143
本文介绍了静态类,接口和抽象类的目的是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请回答.

我的问题是,这三件事实时的确切目的和主要目的是什么.

解决方案

它们与实时无关.让我解释一下它们是什么:

静态类是所有方法和成员都是静态的类,也就是说,没有类实例.这意味着您不必实例化它,您可以按原样使用它.这与具有静态访问器方法和私有构造函数的普通类不同,在普通类中,访问器用于返回该类的实例.

抽象类是一个类,它定义了一些功能以及可能需要提供某些行为的某些方法,但是无法实例化该类.这意味着该类必须具有从其派生的具体实现才能被调用.

接口是合同.仅此而已.它指出您的类将提供某些方法的实现.因此,接口不能具有诸如方法实现或字段定义之类的项.您可能已经知道,C#不允许您使用多重继承-但是您可以做的是,在一个类上具有多个接口.与其他两件事.除此之外,今天已经在这里提出并回答了这个问题.使用google会给您答案.


您的问题太笼统,答案太久了,无法解释.
您可以在msdn上看到它的完整信息,并带有示例:

摘要 [界面 [静态 [ 解决方案

They have nothing to do with real time. Let me explain what they are:

A static class is a class where all methods and members are static, in other words there is no class instance. This means that you don''t have to instantiate it, you can just use it as it is. This is different from an ordinary class with a static accessor method and a private constructor where the accessor is used to return an instance of the class.

An abstract class is a class which defines some functionality, and optionally some methods that you are expected to provide behaviour for, but the class cannot be instantiated. This means that the class must have a concrete implementation that derives from it to be called.

An interface is a contract. Nothing more, nothing less. It states that your class will provide implementations of certain methods. As such, an interface cannot have items such as method implementations, or field definitions. As you may be aware, C# does not allow you to use multiple inheritance - what you can do though, is have multiple interfaces on a class.


A static class has nothing at all to do with the other two things. Besides that, this question has been asked and answered here once already today. Using google will give you your answers.


Your question is too general,and the answer is too long to explain.
You can see on the msdn, it is complete and with example:

Abstract[^]

Interface[^]

Static[^]

If you have a specific question, does not dither.


这篇关于静态类,接口和抽象类的目的是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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