编译错误:并非所有代码路径都返回值

编程入门 行业动态 更新时间:2024-10-27 02:18:17
本文介绍了编译错误:并非所有代码路径都返回值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

朋友们, 我的代码有什么问题,给我一个错误?

Hi friends, What''s the problem of my code that gives me an error?

public int f() { int x = 8; int y = 8; PictureBox[,] pic = new PictureBox[8, 8]; for (int i = 0; i < x; i++) { for (int j = 0; j < y; j++) { pic[i, j] = pictureBox34; Console.WriteLine(String.Format("[i,j] = [{0},{1},{2}]", i, j)); } } ... ...

推荐答案

您的方法返回一个int public int f() 因此,它必须返回一个值 Your method returns an int public int f() So, it has to return a value public int f() { int x = 8; int y = 8; PictureBox[,] pic = new PictureBox[8, 8]; for (int i = 0; i < x; i++) { for (int j = 0; j < y; j++) { pic[i, j] = pictureBox34; Console.WriteLine(String.Format("[i,j] = [{0},{1},{2}]", i, j)); } } return x; // what do you want to return?? }

如果不需要返回值,请使用void public void f()

If you don''t need a return value, use void public void f()

阿鲁什, 您发布的函数还不完整,但是从编译错误中我可以看到您没有在某些代码路径中返回int. 这意味着在您的功能中,如果您有其他陈述, 在某些但不是所有分支中都有return语句. 并且确保在函数定义的右括号之前没有返回语句. 如果需要更多说明,请随时对此评论发表评论. 干杯, 曼弗雷德(Manfred) Hi Arash, the function you posted isn''t complete, but from your compilation error I can see that you''re not returning an int in some code paths. This means that further down in your fucntion you have some if statments and there are return statements in some but not all branches. And for sure there is no return statment right before the closing brace of the function definition. If I need to do more explaining, please feel free to post a comment to this answer. Cheers, Manfred

更多推荐

编译错误:并非所有代码路径都返回值

本文发布于:2023-11-10 01:19:53,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1573968.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:路径   返回值   错误   代码

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!