更新了评论
namespace Task_1._13
{
class Program
{
static void Main(string[] args)
{
// gettingMaximum(int i); This won't work because the int can't be declared while it's being passed into the method
int i = 0; // You need to declare the i before you pass it to a method. Although look closely at your method and the reason you are passing in a value. Do you need it or use it?
Console.WriteLine(gettingMaximum(i)); // I'm outputting the results to the screen so that you can verify that at least something happened
}
public static int gettingMaximum(int z)//; You don't need the semicolon here
// Also, I renamed this to z to demonstrate that you never use it. You could just as easily remove it
// Also, this method must be marked static which is outside the scope of this question
{
int maximum = 0;
int[] myArray = new int[10];
Random rand = new Random();
// This looks good. You create the array and loop through the items and set the value
for (int i = 0; i < myArray.Length; i++)
{
myArray[i] = rand.Next(19);
}
// This code counts to 10. During each step, it compares the current step with 0.
// If the step (i) is 0, you set the maximum to to that value.
// Otherwise, you see if the array value at that step is LESS than the current maximum, and if it is
// you set the maximum to be that value.
//for (int i = 0; i < 10; i++)
//{
// if (i == 0)
// maximum = myArray[i];
// else
// if (myArray[i] < maximum) maximum = myArray[i];
// int result = i; // Here, you're actually setting the result to the current step number
// return result; // I think you meant to set it to maximum, but you can leave it out completely and just return maximum.
//}
for (int i = 0; i < 10; i++)
{
if (i == 0)
{
maximum = myArray[i];
}
else
{ // Since you have nested if's, i'm using braces to illustrate the paths of the branches
if (myArray[i] > maximum) // What i think you mean is, is the value at this item in the array MORE than my current maximum
{
maximum = myArray[i];
}
}
}
return maximum;
}
}
}