术语“函数”是指“函数”吗?在 C# 中有效吗?
我刚刚开始计算机学位的第三年,并且一直在浏览课程材料。我的应用程序开发模块基于 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
C# 3.0 规范说
当然,“匿名函数”正是用这个术语来称呼的。短语“函数成员或匿名函数”在规范中出现很多次,显然没有准确的更简短的方式来表示“可执行代码块”。
The C# 3.0 spec says
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".
嗯,根据定义,函数是返回值的东西,并且不应该有任何副作用。函数式编程将这种范式发挥到了极致。
相反,操作或子例程可能没有返回值,而是有一些副作用。命令式编程依赖于这样的东西。我使用的唯一一种主动强制您声明这一点的语言是 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.