简体   繁体   English

`class`关键字和用户定义的数据类型

[英]The `class` keyword and User-Defined data types

The title may be a bit weird. 标题可能有点怪异。 I don't know how to title this question in a better way. 我不知道如何用更好的方式来称呼这个问题。

Suddenly, I got extremely confused about data types. 突然之间,我对数据类型感到非常困惑。 If a Class is a User-Defined data type, what does the keyword class do? 如果类是用户定义的数据类型,则关键字class做什么?

For example: 例如:

    internal class MyClass
    {
    }

    static class Main
    {

        static int Main(string[] args)
        {
            MyClass mc = new MyClass();
        }

     }

So here, is the user-defined data type MyClass? 因此,这里是用户定义的数据类型MyClass吗? If so, what does the keyword class do? 如果是这样,关键字class做什么?

I thought class was just a blueprint for your user-defined data type. 我认为class只是您用户定义的数据类型的蓝图。 I'm not so sure anymore. 我不太确定了。

If you don't understand the question, please comment so I can maybe try to make it more clear. 如果您不明白该问题,请发表评论,以便我可以尝试使其更加清晰。

There are various categories of user-defined types - class is just one of them; 用户定义的类型有多种类别- class只是其中之一; see also: 也可以看看:

  • struct
  • enum
  • delegate
  • interface

Here, class tells the compiler that you are defining a reference-type single-inheritance type. 在这里, class告诉编译器您正在定义引用类型的单继承类型。

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

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