首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >错误CS0177:在控件离开当前方法之前,必须将out参数'Wx‘赋值给

错误CS0177:在控件离开当前方法之前,必须将out参数'Wx‘赋值给
EN

Stack Overflow用户
提问于 2010-03-25 10:35:41
回答 2查看 11.2K关注 0票数 0
代码语言:javascript
运行
复制
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。我的最终goal...once编译问题都解决了,就是用这个方法来传递列出的每个数组值。这将允许绘制4个xy点对。

错误:

代码语言:javascript
运行
复制
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
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2010-03-25 10:41:11

把这个放在你的方法的开头:

代码语言:javascript
运行
复制
Wx = 0f;
Wy = 0f;
Vx = 0f;
Vy = 0f;
票数 0
EN

Stack Overflow用户

发布于 2010-03-25 10:42:20

我认为这个错误消息是不言而喻的。只需放入

代码语言:javascript
运行
复制
Wx = Wy = 0;
Vx = Vy = 0;

在方法的顶部。我可以从您的逻辑中看出,代码保证在返回之前将值设置为某个值,但是编译器用来确定这一点的静态分析相对简单,有时还有点悲观。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/2512776

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档