Standard C# program blocks

Computers

Members
Class members are either class or instance members. Static members belong to the class as a whole, and instance members belong to specific objects (class instances).

Listed below are the types of members that can be contained in a class.

  • Constants. Constant values associated with a class.
  • Fields: variables associated with the class.
  • Methods: actions that can be performed by the class
  • Properties. Actions related to reading and writing named properties of a class.
  • Indexers. Actions that implement the indexing of class instances to refer to them as an array.
  • Events. Notifications that can be created by this class.
  • Operators. Conversion operators and expressions supported by the class.
  • Constructors. Actions required to initialize instances of a class or the class as a whole.
  • Completion methods: actions performed before the final deletion of instances of a class.
  • Types. Nested types declared in a class.

Accessibilities.
Each member of a class has a certain accessibility level. It determines from which area of the program this member can be accessed. There are six levels of accessibility. The following are the accessibility modifiers.

  • public. The access is not limited.
  • private. Access is possible only from this class.
  • protected. Access is possible from this class and classes derived from it.
  • internal. Access is limited to the current assembly (.exe or .dll).
  • protected internal. Access is limited to this class, classes derived from this class or classes in the same assembly.
  • private protected. Access is limited to the given class or classes derived from the given type in the same assembly.

Fields
A field is a variable associated with a particular class or instance of a class.

A field declared with a static modifier is static. A static field defines strictly one storage location. Regardless of how many instances of that class are created, there is only one copy of the static field.

A field declared without static modifier is an instance field. Each instance of a class contains separate copies of all instance fields defined for that class.

Methods
A method is a member that implements a calculation or action that an object or class can perform. Static methods are accessed through the class. Instance methods are accessed through an instance of the class.

A list of parameters can be defined for a method, which represent the values or variable references passed to the method. Methods have a return type, which specifies the type of value calculated and returned by the method. The return value type of a method is void if it does not return a value.

Like types, methods can have a set of type parameters for which type arguments must be specified when calling a method. Unlike types, type arguments can often be derived from method call arguments, in which case they do not need to be specified explicitly.

The method signature must be unique within the class in which the method is declared. The method signature includes the method name, the number of type parameters, and the number, modifiers, and types of method parameters. The method signature does not include the type of the return value.

Parameters
Parameters allow you to pass values or references to variables into the method. Actual values are assigned to method parameters based on the arguments given when the method is called. There are four types of parameters: value parameters, reference parameters, output parameters, and parameter arrays.

The value parameter is used to pass input arguments. The value parameter is mapped to a local variable, which will get its initial value from the value of the argument passed in that parameter. Changes to the value parameter do not affect the argument passed for that parameter.

Value parameters can be made optional by specifying default values for them. Then the corresponding arguments can be omitted.

Edit