方法和功能之间的差异 [英] difference between method and function

查看:123
本文介绍了方法和功能之间的差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

asp.net C#4.0中的功能和方法之间的区别是什么?

What is The Difference Beetween function and method in asp.net C#4.0

推荐答案

在当今的时代,功能和方法之间没有真正的区别.他们是一样的东西.术语方法和功能"在很大程度上取决于语言.人们倾向于对某些语言使用名称方法,而对其他语言使用功能.

C ++ -函数独立存在,方法是类的成员."

C#-方法是包含一系列语句的代码块."
-通过指定访问级别,返回值,
在类或结构中声明方法. 方法的名称以及任何方法参数.方法参数用括号括起来,
并以逗号分隔."

VB -方法是类中内置的过程."
"VB .NET中有两种方法:返回值(函数)的方法和执行方法的
不返回值(子过程)."

C -在C中,没有诸如方法之类的术语.功能术语被广泛接受,而不管
是否返回某物.

我的建议是使用语言规范中使用的术语.
例如.在c语言中编程时,请全部使用术语函数.
在vb中进行编程时,请对通用术语使用方法,对返回对象的对象使用函数
对于不返回对象的对象,则使用子过程.
In today''s time there is no real difference between functions and methods. They are the same thing. The term method and function is very much language dependant. People tend to use the name method for certain languages and function for others.

C++ - "Functions stand alone and methods are members of a class."

C# - "A method is a code block containing a series of statements."
- "Methods are declared within a class or struct by specifying the access level, the return value,
the name of the method, and any method parameters. Method parameters are surrounded by parentheses,
and separated by commas."

VB - "A Method is a procedure built into the class."
"There are two types of methods in VB .NET: those that return a value (Functions) and those that do
not return a value (Sub Procedures)."

C - In C there is no such term as methods. The term, function, is accepted across the board regardless of
whether is returns something or not.

My advice would be to use the term which the language specification uses.
E.g. When programming in c, use the term function for all.
When programming in vb, use methods for the general term and function for those returning an object
and the term sub-procedure for those that does no return an object.


转到此链接
http://stackoverflow.com/questions/155609/方法和功能之间的区别是什么 [
go this link
http://stackoverflow.com/questions/155609/what-is-the-difference-between-a-method-and-a-function[^]


从历史上看,在某些语言中,有一个概念(并且仍然是功能过程;函数是那些返回一些对象的函数,而过程是什么都不返回的函数.在C/C ++中,这两个函数都被称为函数,并且为了避免过程的概念,发明了人工类型void.这样,过程似乎是函数,但返回void.

在像Basic和Pascal这样的语言中,仍然有函数和过程(sub(Basic中的子例程),在Basic中).后来,在对象Pascal中,作为某些类成员的函数和过程都获得了方法的名称.比较:VMT =虚拟 Method 表,与带有vtbl的C ++相反.

现在,Object Pascal和Delphi成为C#和.NET的主要前身.就像.NET中的每个方法都只能是类或结构的成员一样,各种方法始终称为方法.由于C#中使用的结果类型void的含义与C/C ++中的含义相同,因此不需要特别区分函数和过程.

就我所知,这就是整个故事.

—SA
Historically, in some languages there was a notion (and still is) of functions and procedures; with functions being those returning some objects and procedures returning nothing. In C/C++ both were called functions, and to avoid notion of procedures, the artificial type void was invented. In this way, procedures appeared to be functions but returning void.

In languages like Basic and Pascal there are still functions and procedures (sub (subroutines like in Fortran) in Basic). Later on, in Object Pascal the functions and procedures being the members of some class both got the name of methods. Compare: VMT = Virtual Method Table, in contrast to C++ with vtbl.

Now, Object Pascal and Delphi became a major predecessor of C# and .NET. As in .NET every method can be only a member of a class or structure, all kinds of method are always called methods. As the result type void is used in C# in the same meaning as in C/C++, there is no special need to make difference between functions and procedures.

That''s the whole story, to best of my knowledge.

—SA


这篇关于方法和功能之间的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆