接口,抽象类,区别密封类,静态类和部分类在C#中? [英] Difference between Interface, abstract class, sealed class, static class and partial class in C#?

查看:188
本文介绍了接口,抽象类,区别密封类,静态类和部分类在C#中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

接口,抽象类,密封类,静态类和部分类在C#之间的区别?如果在vb.net中所有可用类?

Difference between Interface, abstract class, sealed class, static class and partial class in c#? If all classes available in vb.net?

推荐答案


  • 抽象类结果
    当有IS-A的关系,应使用并没有实例应该允许从该抽象类创建。
    例如:动物是一个抽象基类,其中具体的动物可以得到,即马,猪等。
    通过使抽象的动物是不允许创建一个实例动物

  • abstract classes
    Should be used when there is a IS-A relationship and no instances should be allowed to be created from that abstract class. Example: An Animal is an abstract base class where specific animals can be derived from, i.e. Horse, Pig etc. By making Animal abstract it is not allowed to create an Animal instance.

    接口结果
    接口应使用一个类来实现功能。假设我们要一匹马,能够跳,接口IJumping可以被创建。通过增加这个接口马,在IJumping所有方法应该实施。在仅IJumping本身的声明(例如StartJump和EndJump定义),在马应加入这两种方法的实施方式。

    interface
    An interface should be used to implement functionality in a class. Suppose we want a horse to be able to Jump, an interface IJumping can be created. By adding this interface to Horse, all methods in IJumping should be implemented. In IJumping itself only the declarations (e.g. StartJump and EndJump are defined), in Horse the implementations of these two methods should be added.

    密封类结果
    通过使马密封,它是无法从它,例如继承制作班像小马或主力,你想从马继承。

    sealed class
    By making Horse sealed, it is not possible to inherit from it, e.g. making classes like Pony or WorkHorse which you like to be inheriting from Horse.

    静态类结果
    主要用于'实用'功能。假设你需要一些方法来计算在马类中使用的一些数字的平均水平,但你不想把在马,因为它是不相关的,它也没有相关的动物,你可以创建一个类来有这样的方法。你并不需要这样一个实用工具类的一个实例。

    static class
    Mostly used for 'utility' functions. Suppose you need some method to calculate the average of some numbers to be used in the Horse class, but you don't want to put that in Horse since it is unrelated and it also is not related to animals, you can create a class to have this kind of methods. You don't need an instance of such a utility class.

    部分类结果
    分部类无非是一个类的文件分割成多个小文件的更多。一个原因要做到这一点可能是共享源$ C ​​$ C他人的一部分。如果原因是文件变得太大,想想分裂小班第一类。

    partial class
    A partial class is nothing more than splitting the file of a class into multiple smaller files. A reason to do this might be to share only part of the source code to others. If the reason is that the file gets too big, think about splitting the class in smaller classes first.

    这篇关于接口,抽象类,区别密封类,静态类和部分类在C#中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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