M
Martin
Hi all,
In the following example, I'd like to replace int by a generic. In
order word, I would like to replace int by float, double, byte or
something like that. I've tried to find a common interface or
something like that, but I didn't find.
public static int MaxSum(int[] source)
{
int maxSoFar = 0, maxEndingHere = 0;
for (int i = 0; i < source.Length; i++)
{
maxEndingHere = Math.Max(maxEndingHere + source,
0);
maxSoFar = Math.Max(maxSoFar, maxEndingHere);
}
return maxSoFar;
}
In would like to replace this method signature by public static T
MaxSum<T>(T[] source) where T : I???. Thank you for your help.
Martin
In the following example, I'd like to replace int by a generic. In
order word, I would like to replace int by float, double, byte or
something like that. I've tried to find a common interface or
something like that, but I didn't find.
public static int MaxSum(int[] source)
{
int maxSoFar = 0, maxEndingHere = 0;
for (int i = 0; i < source.Length; i++)
{
maxEndingHere = Math.Max(maxEndingHere + source,
0);
maxSoFar = Math.Max(maxSoFar, maxEndingHere);
}
return maxSoFar;
}
In would like to replace this method signature by public static T
MaxSum<T>(T[] source) where T : I???. Thank you for your help.
Martin