這樣不對using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace _6._5{??? class Program??? {??????? static void Main(string[] args)??????? {??????????? int? dt = DateTime.Now.Month ;??????????? Console.WriteLine("您現(xiàn)在處于{0}月", dt);??????????? string w1 ; ??????????? switch (dt)??????????? {??????????????? case 12:??????????????? case 1:??????????????? case 2: w1 = "您現(xiàn)在處于冬季!"; break;??????????????? case 3:??????????????? case 4:??????????????? case 5: w1 = "您現(xiàn)在處于春季!"; break;??????????????? case 6 :??????????????? case 7 :??????????????? case 8: w1 = "您現(xiàn)在處于夏季!"; break;??????????????? case 9 : ??????????????? case 10 :??????????????? case 11: w1 = "您現(xiàn)在處于秋季"; break; ??????????? }??????????? Console.WriteLine(w1);??????????? Console.ReadLine();??????? }??? }}但是這樣就對了。。。using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace _6._5{??? class Program??? {??????? static void Main(string[] args)??????? {??????????? int? dt = DateTime.Now.Month ;??????????? Console.WriteLine("您現(xiàn)在處于{0}月", dt);??????????? string w1 =""; ??????????? switch (dt)??????????? {??????????????? case 12:??????????????? case 1:??????????????? case 2: w1 = "您現(xiàn)在處于冬季!"; break;??????????????? case 3:??????????????? case 4:??????????????? case 5: w1 = "您現(xiàn)在處于春季!"; break;??????????????? case 6 :??????????????? case 7 :??????????????? case 8: w1 = "您現(xiàn)在處于夏季!"; break;??????????????? case 9 : ??????????????? case 10 :??????????????? case 11: w1 = "您現(xiàn)在處于秋季"; break; ??????????? }??????????? Console.WriteLine(w1);??????????? Console.ReadLine();??????? }??? }}但是課本上明明就是第一種寫法啊,我的報錯,使用了未賦值的變量w1.。。。。。明明已經(jīng)賦值。。。。QwQ
- 2 回答
- 0 關(guān)注
- 1529 瀏覽
添加回答
舉報
0/150
提交
取消