首页 > > > 我在for循环语句给变量S赋值
我在for循环语句给变量S赋值,但程序报错:使用了未赋值的局部变量“s”,希望老师们指导
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5
6 namespace 数组的排序练习
7 {
8 class Program
9 {
10 static void Main(string[] args)
11 {
12 string[] names = { "梅西", "卡卡", "郑大世" };
13 string s;
14 //在for循环语句不是个s赋值了,怎么还是报错“局部变量S未赋值”
15 for (int i = 0; i < names.Length-2; )
16 {
17 s=names[i]+"|";
18 Console.Write(s);
19 i++;
20 }
21 s=s+names[names.Length-1];
22 Console.WriteLine(s);
23
24 Console.ReadKey();
25 }
26 }
27 }程序报错:使用了未赋值的局部变量“s”(即代码中的红色s),可是我不是在for语句中,已经赋值初始化了吗?
希望各位老师们,指导学生,指点迷津
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/4809/viewspace-3144281/ ,如需转载,请注明出处,否则将追究法律责任。