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

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

Stud_Information为红色且此错误: 'Learning.Stud():'并非所有代码路径都返回值。 我用Stud方法调用学生课。但是这个错误。为什么要收到这个错误信息? 我试过的: Student.cs

Stud_Information is red and this error : 'Students.Stud():' not all code paths return a value. I call Students class in Stud method.But take this error.Why take this error message? What I have tried: Student.cs

namespace WorkList { public class Stud_Information { public List<string> students= new List<string>(); public static string Stud() { List<string> students = new List<string>(); students.Add("Mary"); } } }

计划.cs

Program.cs

namespace WorkList { class Program { static void Main(string[] args) { Stud_Information.Stud(); for (var i = 0; i < students.Count; i++) { Console.WriteLine("[" + i.ToString() + "] " + students[i] ); } Console.ReadKey(); } }

推荐答案

你的 Stud()方法被定义为返回一个字符串的值,你没有返回。 要么返回方法中的字符串值:返回Mary; 或者将方法定义更改为return void: public static void Stud() Your Stud() method is defined as returning a string value which you are not returning. Either return a string value in the method : return "Mary"; Or change the method definition to return void : public static void Stud()

更多推荐

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

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

发布评论

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

>www.elefans.com

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