To the OP: what follows here may seem "academic," but the key point is that C# does not make the formal distinction between
methods and
functions that other programming languages
require different syntax to express.
In communication with other programmers it may be useful if you describe a method that returns a value of some Type as a function, and refer to methods that return Type 'void as a method.
Mehdi Gholam is absolutely right when he points out that in
common usage, in most programming languages, the distinction between methods and functions is that a function always returns a value, and a method does not return a value.
But, in C#, there's no special syntax for distinguishing between methods and functions ! All procedures (methods or functions) must specify a return Type: specifying a return Type of 'void is a way of telling the compiler that a method does not return a value.
The C# Programming Language specification [
^] describes a method as:
"8.7.3 Methods
A method is a member that implements a computation or action that can be performed by an object or class. Methods have a (possibly empty) list of formal parameters, a return value (unless the method’s return-type is void), and are either static or non-static. Static methods are accessed through the class. Non-static methods, which are also called instance methods, are accessed through instances of the class. A generic method (§25.6) has a list of one or more type parameters."
The C# spec does frequently use the term "function members," as an over-arching summary category for all of: "static methods, static property accessors, and user-defined operators. Instance function members. These are instance methods, instance constructors, instance property accessors, and indexer accessors." See section 14.4.
Nowhere in the C# specification will you find a discussion of "functions" compared to "methods." And, you won't find the term "anonymous functions," or "lambda" in the spec, either.
In C# methods can be defined in both Classes, and Structs; and, yes, Structs can have static methods, even though a Struct cannot be defined as static: I've never been able to find a reason to use that feature :)