public class Form1 : System.Windows.Forms.Form
{
private void eachCornerPix (object sender, PaintEventArgs e, out float Wx, out float Wy, out float Vx, out float Vy)
{
Graphics g = this.CreateGraphics();
Pen penBlu = new Pen(Color.Blue, 2);
SolidBrush redBrush = new SolidBrush(Color.Red);
int width = 2; // 1 pixel wide in x
int height = 2;
float [] Wxc = {0.100f, 5.900f, 5.900f, 0.100f};
float [] Wyc = {0.100f, 0.100f, 3.900f, 3.900f};
for (int i = 0; i<3; i++)
{
Wx = Wxc[i];
Wy = Wyc[i];
Vx = ((Wx - WXmin)*((VXmax-VXmin)+VXmin)/(WXmax-WXmin));
Vy = ((Wy - WYmin)*(VYmax-VYmin)/(WYmax-WYmin)+VYmin);
Console.WriteLine("eachCornerPix Vx= {0}", Vx);
Console.WriteLine("eachCornerPix Vy= {0}", Vy);
g.FillRectangle(redBrush, Vx, Vy, width, height);
g.Dispose();
}
}
}
所需效果:使用数组值(Wxc,Wyc)并将它们重新分配给Wx和Wy。然后用 Wx和Wy作为计算Vx和Vy的组件。 我的最终目标......一旦编译问题得到解决,就是传递列出的每个数组值 使用这种方法。这应该允许绘制4个xy点对。
错误:
pass1.cs(51,18): error CS0177: The out parameter 'Wx' must be assigned to before control leaves the current method
pass1.cs(51,18): error CS0177: The out parameter 'Wy' must be assigned to before control leaves the current method
pass1.cs(51,18): error CS0177: The out parameter 'Vx' must be assigned to before control leaves the current method
pass1.cs(51,18): error CS0177: The out parameter 'Vy' must be assigned to before control leaves the current method
答案 0 :(得分:3)
我认为错误信息非常明显。只需加上
Wx = Wy = 0;
Vx = Vy = 0;
位于方法的顶部。我可以从你的逻辑中看出,代码保证在返回之前将值设置为某个值,但编译器用来确定它的静态分析相对简单,有时候有些悲观。
答案 1 :(得分:0)
将它放在方法的开头:
Wx = 0f;
Wy = 0f;
Vx = 0f;
Vy = 0f;