Re: [問題] C#新手連compile都不過的語法請教
namespace ConsoleApplication1
{
class stars {
public string name;
public string skey;
}
class Program
{
stars star1 = new stars();
star1.name = "劉德華"; //這兩行只准出現在function裡面
star1.skey = "ㄌㄉㄏ"; //
// 我想問這裡有沒有辦法把三行縮成 stats star1 = new stars("劉德華","ㄌㄉㄏ");
想這樣做的話請補上建構子:
public stars(string _name,string _skey)
{/*指定name、skey的值*/}
// 這邊的兩行的等於他都說有問題 類別、結構或介面成員宣告中無效的語彙基元'='
static void Main(string[] args)
{
string enterName;
for (;;) {
xm = Console.ReadKey();
if (string.StartsWith(star1.skey, enterName))
{
Console.WriteLine("{0}", star1.name);
}
else
{
Console.WriteLine("none");
}
}
//主要就是輸入 索引例如我輸入ㄌㄉㄏ 跟劉德華的KEY比對發現是一樣的話 就印出找到
//的姓名 這邊我是希望就算我只輸入ㄌㄉ也能達到同樣效果所以採取StartsWith的函式
有陣子沒寫C#了
你翻翻看MSDN看看說明怎麼寫,我覺得用StartsWith()比對好像怪怪的
//
}
}
}
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 175.45.25.41
推
10/24 16:25,
10/24 16:25
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 114.33.58.232
→
10/24 17:40, , 1F
10/24 17:40, 1F
→
10/24 17:41, , 2F
10/24 17:41, 2F
→
10/24 17:41, , 3F
10/24 17:41, 3F
→
10/24 22:32, , 4F
10/24 22:32, 4F
→
10/24 22:33, , 5F
10/24 22:33, 5F
→
10/24 22:34, , 6F
10/24 22:34, 6F
推
10/25 13:50, , 7F
10/25 13:50, 7F
討論串 (同標題文章)
完整討論串 (本文為第 2 之 2 篇):