C#Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.
You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Below one of my many array functions. I don't know if .NET Framework contains one at least I could not find one. Use this at your own risk. I never tested it extensively but it should work. Based on the algorithm you can write your own version, maybe more effective than mine. As so for searching the min. value. And of course write some error handling for it.
In the past i wrote three versions and this should be the correct one. If not let me know.
public int f_array_max_int (int[] p_array)
{
int ArrayLength = p_array.Length;
int MaxValue = p_array[0];
for (int i = 0; i < ArrayLength; i++)
{
foreach (int TempValue in p_array)
{
if (TempValue >= MaxValue)
{
MaxValue = TempValue;
}
}
These are my revised versions of finding min. and max. values in an array. You can better use these ones. The performance is much better than previous one.
Find max. value in array:
public double f_array_max (double[] p_array)
{
Array.Sort(p_array);
return p_array[p_array.Length-1];
}
Find min. value in array:
public double f_array_min (double[] p_array)
{
Array.Sort(p_array);
return p_array[0];
}