Method Parameters - CSharp Custom Type

CSharp examples for Custom Type:Method Parameter

Introduction

A method has a sequence of parameters.

Parameters define the set of arguments that must be provided for that method.

Demo Code

using System;//w ww.  j a  v a2  s  . c  o  m
class Test
{
   static void Foo (int p)
   {
      p = p + 1;                 // Increment p by 1
      Console.WriteLine (p);     // Write p to screen
   }
   static void Main()
   {
      Foo (8);                  // Call Foo with an argument of 8
   }
}

Result

You can control how parameters are passed with the ref and out modifiers:

Parameter modifierPassed by Variable must be definitely assigned
(None) Value Going in
ref Reference Going in
out Reference Going out

Related Tutorials