Declare function in c#



You can declare a function to work separate task and you can use in the main function.

This is none return type function
  1. public void DoStuff()  
  2. {  
  3.     Console.WriteLine("I'm doing something...");  
  4. }  
This is return type function
  1. public int AddNumbers(int number1, int number2)  
  2. {  
  3.     int result = number1 + number2;  
  4.     if(result > 10)  
  5.     {  
  6.     return result;  
  7.     }  
  8. }  
 Add in void main
  1. int result = AddNumbers(12, 3);  
  2. Console.WriteLine(result);  
 

0 Comment's

Comment Form

Submit Comment