Here is another simple C Sharp dotnet interview question.
There is a piece of code in C# Dotnet as written below. The function takes a number array as input and returns the largest number. It has few bugs in it. Find out the bugs and fix them.
{
int max = int.MaxValue;
for (int i = 0; i < list.Length - 1; i++)
if (list[i] > max)
max = list[i];
return max;
}
You can post the answers as comments. Thank you.
There is a piece of code in C# Dotnet as written below. The function takes a number array as input and returns the largest number. It has few bugs in it. Find out the bugs and fix them.
Code :
public static int Largest(int[] list){
int max = int.MaxValue;
for (int i = 0; i < list.Length - 1; i++)
if (list[i] > max)
max = list[i];
return max;
}
You can post the answers as comments. Thank you.