术语“函数”是指“函数”吗?在 C# 中有效吗?

发布于 2024-12-08 08:55:30 字数 164 浏览 0 评论 0原文

我刚刚开始计算机学位的第三年,并且一直在浏览课程材料。我的应用程序开发模块基于 C#。在整个材料中,讲师将我所知道的所谓“方法”称为“函数”。我知道术语“函数”(例如)C++ 用作代码块,但我认为 OOP 使用“方法”来区分两种不同类型的编程。

那么,两者可以互换吗?还是讲师应该使用“方法”一词?

Ive just started year three of my computing degree and have been looking through the course material. My application development module is based around c#. Throughout the material the lecturer refers to what I know to be called 'methods' as 'functions'. I am aware that the term 'functions' is used (for example) c++ for as code block but I thought that OOP used 'method' to distinguish between the two different types of programming.

So, are the two interchangeable or should the lecturer be using the term 'methods'?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

前事休说 2024-12-15 08:55:30

C# 3.0 规范说

1.3

类类型定义包含数据成员的数据结构
(字段)和函数成员(方法、属性等)。

1.6.7

包含可执行代码的成员统称为
类的函数成员。上一节描述了方法,
这是主要的函数成员类型。本节描述
C# 支持的其他类型的函数成员:构造函数、
属性、索引器、事件、运算符和析构函数。

当然,“匿名函数”正是用这个术语来称呼的。短语“函数成员或匿名函数”在规范中出现很多次,显然没有准确的更简短的方式来表示“可执行代码块”。

The C# 3.0 spec says

1.3

A class type defines a data structure that contains data members
(fields) and function members (methods, properties, and others).

1.6.7

Members that contain executable code are collectively known as the
function members of a class. The preceding section describes methods,
which are the primary kind of function members. This section describes
the other kinds of function members supported by C#: constructors,
properties, indexers, events, operators, and destructors.

And of course "anonymous functions" are called by exacly that term. The phrase "function member or anonymous function" occurs a lot in the spec, there apparently being no accurate shorter way to say "lump of executable code".

晨曦÷微暖 2024-12-15 08:55:30

嗯,根据定义,函数是返回值的东西,并且不应该有任何副作用。函数式编程将这种范式发挥到了极致。

相反,操作或子例程可能没有返回值,而是有一些副作用。命令式编程依赖于这样的东西。我使用的唯一一种主动强制您声明这一点的语言是 Visual Basic(子函数和函数)。在 C# 中,如果没有经典意义上的函数,则只需将 void 声明为返回类型。

据我所知,“方法”一词是为了将面向对象编程与其他风格区分开来而创造的。作为对象的一部分(成员)的函数将是一个方法。

我希望这有帮助。

Well, by definition a function is something that returns a value and should not have any side effects. Functional programming takes this paradigm to the extreme.

In contrast an operation or sub routine may have no return value and instead have some side effect. Imperative programming relies on things like this. The only language I worked with that actively forced you to declare this was Visual Basic (sub and function). In C# you just declare void as return type if you do not have a function in the classic sense.

The term method was AFAIK coined to distinguish object oriented programming from other styles. A function which is part (member) of an object would be a method then.

I hope that helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文