简体   繁体   English

C#抽象类

[英]C# Abstract Class

Does a compiler compiles an abstract class in C#? 编译器是否在C#中编译抽象类?

If yes then how does compiler treats an abstract class, like a normal class or there is some difference. 如果是,那么编译器如何对待抽象类,如普通类,还是有一些区别。

And if no then how does it allow inheritance of the data members and a member function of an abstract class in derived class. 如果否,那么它将如何允许数据成员和派生类中抽象类的成员函数的继承。

An abstract class indeed behaves like a normal class in IL, the only difference is the added abstract flag/keyword. 抽象类的行为确实类似于IL中的普通类,唯一的区别是添加了abstract标志/关键字。

A generic public class in IL looks like this (without body) IL中的通用公共类如下所示(无主体)

.class public auto ansi beforefieldinit 
  NAMESPACE.CLASS_NAME
    extends [mscorlib]System.Object

an abstract class looks like this 一个抽象类看起来像这样

.class public abstract auto ansi beforefieldinit 
  NAMESPACE.CLASS_NAME
    extends [mscorlib]System.Object

I can recommend you creating test assemblys and browsing them with dotPeek from JetBrains (its a free tool). 我可以建议您创建测试程序集,并使用JetBrains(免费工具)中的dotPeek浏览它们。 You can look trough the code and the IL code at the same time. 您可以同时查看代码和IL代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM