What is function creation ? how is create function? with example program c# code
What is function? how is create function? with example program c# code
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
Satyapriya NayakRank #47 · 31.5K reputationPosted Jul 7, 2012, 2:27 AM EDT
A function allows you to encapsulate a piece of code and call it from other parts of your code. You may very soon run into a situation where you need to repeat a piece of code, from multiple places, and this is where functions come in. In C#, they are basically declared like this:
Next is the type to return. It could be any valid type in C#, or as we have done it here, void. A void means that this function returns absolutely nothing. Also, this function takes no parameters, as you can see from the empty set of parentheses, so it's actually just a tad bit boring. Let's change that:
public int AddNumbers(int number1, int number2) { int result = number1 + number2; return result; }'AddNumbers(int, int)': not all code paths return a value
The compiler is reminding us that we have a function which doesn't return something, although we promised. And the compiler is pretty clever! Instead of removing the line, try something like this:
public int AddNumbers(int number1, int number2) { int result = number1 + number2; if(result > 10) { return result; } }public int AddNumbers(int number1, int number2) { int result = number1 + number2; if(result > 10) { return result; } return 0; }Please refer the below link
http://csharp.net-tutorials.com/basics/functions/
Thanks
VulpesRank #55 · 29.2K reputationPosted Jul 7, 2012, 2:33 AM EDT
Global functions are not supported
Consequently, functions are normally referred to as 'methods' in C# in accordance with OOP terminology.