Navigation

Related Articles

Back to Latest Articles

C# Basics – Functions – Part 10

We get to know how functions work in C# programming language.


Andraz Krzisnik
C# Basics – Functions – Part 10

Functions

We’ve been writing simple programs so far. But when things get more complicated, writing it all into one block of code could become hard to read. We can use functions for executing a block of code whenever the name of the function is called.

Functions are very useful at making your code more readable and easier to fix any errors. We can use a function more than just once and we can even use it in other programs. We have always been using functions through entire tutorial, for example Math.Sqrt() is a function that is already written.

There are a few different ways we can denote functions. We separate static and object functions. We also separate them by what kind of access we have with this function, these can be public, private and protected. For now we will only work with public.

For each function, before we use it, we first need to define it.  First thing, we have to declare, is what kind of access we have to this method (public, private, protected), then we need to set what type is our function, static or objective. What follows after this, is the data type of value our function should return. After that, all we need is the name of the function, and possible arguments this function will take. And lastly, we have to write our code between curly brackets ({}).


Download Examples Next Chapter
Show Comments (0)

Comments

Related Articles

C# Tutorial

C# Tutorial: How To Create Gaussian Blur

Gaussian blur is an image processing operation, that reduces noise in images. It does so by a convolution process, using a matrix that contains values calculated by a Gaussian...

Posted on by Andraz Krzisnik
C# Basics

C# Basics – Constructors – Part 12

Constructors Sometimes we want to create an object and set some predetermined state to it. Basically, you would pass the properties’ values as an argument to an object when you...

Posted on by Andraz Krzisnik