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


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)


Related Articles

C# Basics

C# Basics – Exception Handling Statements – Part 9

Exception Handling Statements Sometimes, there comes a situation that where our code might crash. We can handle these kind of situations with exception handling statements. By...

Posted on by Andraz Krzisnik
C# Tutorial

C# Tutorial: Contrast Stretching with Normalization

This post is a short revision of Contrast Stretch post we already worked on in the past. Where we talked about histogram equalization, which is a little more complex method than...

Posted on by Andraz Krzisnik