The method itself it totally wrong. First parameter is excessive.
numpoints
should be taken from
p
as
p.Length
. You will get into trouble is someone call it with mismatch in the parameters: either not all elements of array will be processed, or there will be the out-of-range exception. Also, never declare look variable before the loop (see the code sample).
Moreover, the method does not use any instance members. So, it should be
static. For better style and maintainability, replace fields with properties:
struct Point {
public int X { get; set; }
public int Y { get; set; }
public static void MyPoly(Point[] points) {
if (points == null) return;
for (int index = 0; index < points; ++index) { }
}
}
Point.MyPoly(new Point[] {1, 2, 3, 4,});
or
struct Point {
public int X { get; set; }
public int Y { get; set; }
}
static class SomeOtherType {
public static void MyPoly(Point[] points) {
if (points == null) return;
for (int index = 0; index < points; ++index) { }
}
}
SomeOtherType.MyPoly(new Point[] {1, 2, 3, 4,});
You have too many bugs and design mistake for such short code. It looks like you did not learn syntax and semantic of the language and .NET. Better start again, from scratch, pay more attention, use less of trial-and-error approach.
—SA