Difference between revisions of "Function"
esse quam videri
(→Example) |
|||
Line 8: | Line 8: | ||
=Example= | =Example= | ||
<syntaxhighlight lang ="csharp"> | <syntaxhighlight lang ="csharp"> | ||
− | string[] shuffleStringArray(string[] targetArray) // By making the array that will be shuffled an argument, we can send any array of string we want into this function. | + | string[] shuffleStringArray(string[] targetArray) // By making the array that will be shuffled an argument, we can send any array of type string we want into this function. |
{ | { | ||
for(int i = 0; i < targetArray.Length; i++) | for(int i = 0; i < targetArray.Length; i++) | ||
Line 19: | Line 19: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | |||
=Resources= | =Resources= |
Latest revision as of 15:24, 22 August 2019
Definition
A funciton is a block of reusable code that performs a single action.
Relevance
Functions are an essential part of programming. The key is to make them reusable to reduce typing the same (or similar) code. Another key is known as the "Single Responsibility Principle" which states each function should only have one responsibility (perform one specified action).
Example
string[] shuffleStringArray(string[] targetArray) // By making the array that will be shuffled an argument, we can send any array of type string we want into this function.
{
for(int i = 0; i < targetArray.Length; i++)
{
// Code for shuffling here
}
return targetArray; // Return the shuffled array to wherever the function was called.
}