Example: "static public int GetMax(int[] tstArr, out int[] maxValInd)"
I keep getting the following errors:
Error 1 Use of unassigned out parameter 'maxValInd'
Error 2 The out parameter 'maxValInd' must be assigned to before control leaves the current method
I have tried everything to get this accepted by the compiler. The only thing I can make work is just passing an integer as an experiment.
The code is as follows:
static void Main(string[] args)
{
Arrays arrays = new Arrays();
int[] testArray = { 4, 7, 1, 4, 2, 1, 8, 7 };
int[] maxValIndices = new int[8];
Console.WriteLine(" Index\tData\tHistogram");
Console.WriteLine();
for (int i = 0; i < testArray.Length; i ++ )
{
Console.Write(" {0}\t{1}\t", i, testArray[i]);
for(int ii = 0; ii < testArray[i]; ii++)
Console.Write("*");
Console.WriteLine();
}
Console.WriteLine("\nMaximum value = " +
"{0} found at element indices: {1}", testArray.Max(),
Array.BinarySearch(testArray, testArray.Max()));
testArray.CopyTo(maxValIndices, 0);
GetMax(testArray, out maxValIndices);
Console.WriteLine();
Console.Write("Press any key to continue...");
Console.ReadKey();
}
static public int GetMax(int[] tstArr, out int[] maxValInd)
{
int myRetVal = 1;
tstArr.CopyTo(maxValInd, 0);
return myRetVal;
}
The error is at: tstArr.CopyTo(maxValInd, 0);
Any help on this would be appreciated! Thanks

New Topic/Question
Reply




MultiQuote











|