Square method used to demonstrate the method call stack and activation records. - CSharp Custom Type

CSharp examples for Custom Type:Method

Description

Square method used to demonstrate the method call stack and activation records.

Demo Code

using System;//from  w w w  .j a v a  2s. co  m
class SquareTest
{
   static void Main()
   {
      int x = 10; // value to square (local variable in main)
      Console.WriteLine($"x squared: {Square(x)}");
   }
   static int Square(int y) // y is a local variable
   {
      return y * y; // calculate square of y and return result
   }
}

Result


Related Tutorials