IcyPopTarts IcyPopTarts - 3 years ago 257
C# Question

Pass Parameters To Method

I am getting an error of


Error CS7036 There is no argument given that corresponds to the required formal parameter 'b2' of 'Form1.checkInfo(PointF, PointF, PointF, PointF, ref PointF)' WindowsFormsApplication1


when I attempt to pass parameters to a method. This is my syntax, and to me it looks like
b2
is declared, and assigned and being passed, but I can not discover what I need to change to make the error go away!

private void button1_Click(object sender, EventArgs e)
{
Point[] points = new Point[] { new Point { X = -100, Y = 0 }, new Point { X = 0, Y = 0 } };
PointF returnedPoint = new PointF();
for (int i = 0; i < points.Count(); i++)
{
float X1value = points[i].X;
float X2value = points[i-1].X;
float Y1value = points[i].Y;
float Y2value = points[i-1].Y;
checkInfo(new PointF(X1value, Y1value), new PointF(X2value, Y2value), ref returnedPoint);
}
}
bool checkInfo(PointF a1, PointF a2, PointF b1, PointF b2, ref PointF returnedPoint)
{
//Do stuff here
}

Answer Source

Error CS7036 There is no argument given that corresponds to the required formal parameter 'b2' of 'Form1.checkInfo(PointF, PointF, PointF, PointF, ref PointF)' WindowsFormsApplication1

Your method checkInfo(PointF a1, PointF a2, PointF b1, PointF b2, ref PointF returnedPoint) takes 5 parameters, but you call it checkInfo(new PointF(X1value, Y1value), new PointF(X2value, Y2value), ref returnedPoint) with only 3 parameters. The error message complains about missing parameters.

Please see my comments below:

private void button1_Click(object sender, EventArgs e)
{
    Point[] points = new Point[] { new Point { X = -100, Y = 0 }, new Point { X = 0, Y = 0 } };
    PointF returnedPoint = new PointF();
    for (int i = 0; i < points.Count(); i++)
    {
        float X1value = points[i].X;
        float X2value = points[i-1].X;
        float Y1value = points[i].Y;
        float Y2value = points[i-1].Y;

        // Error located here: Only 3 parameters passed - You need to pass 2 more instances of 'PointF'
        checkInfo(new PointF(X1value, Y1value), new PointF(X2value, Y2value), ref returnedPoint);
    }
}

// Takes 5 parameters 
bool checkInfo(PointF a1, PointF a2, PointF b1, PointF b2, ref PointF returnedPoint)
{
    //Do stuff here
}
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download