简体   繁体   English

接口数据类型?

[英]Are interfaces data types?

I am viewing tuts+ video titled Design Patterns in C# . 我正在观看标题为C#中的Design Patterns的 tuts +视频。 In it, the instructor says: 在其中,讲师说:

"Interfaces are contracts. They are data types that define properties and methods that we have to implement within a class." “接口是契约。 它们是定义我们必须在类中实现的属性和方法的数据类型 。”

My question: Is this correct, that is, are interfaces really data types in C#? 我的问题:这是正确的吗,也就是说,接口真的是C#中的数据类型吗?

From the C# programming guide : C#编程指南中

C# is a strongly-typed language. C#是一种强类型的语言。 Every variable and constant has a type, as does every expression that evaluates to a value. 每个变量和常量都有一个类型,每个求值的表达式也有一个类型。 Every method signature specifies a type for each input parameter and for the return value. 每个方法签名都为每个输入参数和返回值指定一种类型。

(...) (...)

You use the struct, class, interface, and enum constructs to create your own custom types. 您可以使用结构,类,接口和枚举结构来创建自己的自定义类型。

So yes, interfaces are considered first class types in the .NET world. 所以是的,接口被认为是.NET世界中的一流类型。 Anyway I find the term "data type" confusing in that context, I think that saying just "type" is more correct. 无论如何,在这种情况下,我发现术语“数据类型”令人困惑,我认为仅说“类型”更为正确。

By the term datatype , the instructor must have hinted that Interfaces declare the type that has to be defined later. 通过术语数据类型 ,教师必须暗示接口要声明以后必须定义的类型。

If you consider the usage of an Interface, it does the same. 如果考虑接口的用法,它也会这样做。 It helps us to declare the methods but gives away the freedom to the developers to define it as per their need. 它可以帮助我们声明方法,但让开发人员可以根据自己的需要定义方法。

Hope it clears your doubts. 希望它消除您的疑虑。

Interface can be considered as reference data type. 接口可以视为参考数据类型。

A data type in programming language is a set of data with values having predefined characteristics . 编程语言中的数据类型是一组具有预定义特征值的数据。 In Object Oriented programming, a programmer can create new data types to suit the application requirements. 在面向对象的编程中,程序员可以创建新的数据类型以适合应用程序需求。

With object-oriented programming, a programmer can create new data types to meet application needs. 使用面向对象的编程,程序员可以创建新的数据类型以满足应用程序的需求。 Such an exercise as known as " data abstraction " and the result is a new class of data. 这样的练习称为“ data abstraction ”,其结果是一类新的数据。 Such a class can draw upon the "built-in" data types such as number integers and characters. 这样的类可以利用"built-in"数据类型,例如数字整数和字符。 For example, a class could be created that would abstract the characteristics of a purchase order. 例如,可以创建一个类来抽象采购订单的特征。 The purchase order data type would contain the more basic data types of numbers and characters and could also include other object defined by another class. 采购订单数据类型将包含数字和字符等更基本的数据类型,并且还可能包含由另一个类定义的其他对象。 The purchase order data type would have all of the inherent services that a programming language provided to its built-in data types. 采购订单数据类型将具有编程语言为其内置数据类型提供的所有固有服务。

Source 资源

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

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