C# Function call

  • Thread starter Thread starter Prashant Girennavar
  • Start date Start date
P

Prashant Girennavar

Guest
Hello Experts,

I have started learning C# Programming recently and understand the logic used in C# Program.

At present I am learning fucntions in C# (Using Wrox publication to learn) , and trying to understand how the fuctions work in C#.

I have below code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Ch06Ex02
{
class Program
{
static void Main(string[] args)
{
int[] myarray = { 1, 4, 5, 6, 3, 4, 5, 3, 9, 0 };
int maxval = maxvalue(myarray);
Console.WriteLine("The maximum value of the array is {0}", maxval);
Console.ReadKey();
}
static int maxvalue(int[] intarray)
{
int maxval = intarray[0];
for (int i = 1;i<intarray.Length;i++)
{
if (intarray>maxval)
maxval = intarray;
}
return maxval;
}
}

}
Below is my understanding regarding the code

1).Program Executes Main() functin first and assigns the myarray with sets of array value
2).Then it finds the maxvalue function defined and execute the function MaxValue
3).Maxvalue compares the values and find the highest integer an array and return the value

Is the logic correct here?

Also I have below question

1).int maxval = maxvalue(myarray);

In this line , why we are defining int maxval Cant we just include maxvalue(Myarray);?

2).when program reaches int maxval = maxvalue(myarray); it executes MaxValue Function . Am I right here?

3).Once the MaxValue function execution is done , program will return to console.writeline in Static Void Main () Function?

Please help me in understanding the loop.

Thanks

-Prashant Girennavar.

MCSA|MCITP SA|Microsoft Exchange 2003 Blog - http://prashant1987.wordpress.com Disclaimer: This posting is provided AS-IS with no warranties/guarantees and confers no rights.

Continue reading...
 
Back
Top