我遇到的問題了解C#方法的語法 - 特別是"must return something"
錯誤。方法返回類型的用途
我有這樣的方法:
public static class Connection
{
public static List<string> getClients()
{
List<string> clients = new List<string>();
return clients;
}
}
的方法不正確,因爲我得到invalid expression term "return"
,所以我完全不知道該怎麼辦。有人能解釋我這個公共空白等是如何工作的嗎?
另外,爲什麼我不能做到以下幾點?
public getClients()
{
List<string> clients = new List<string>();
return clients;
}
我得到一個錯誤說method must have a return type
你的第一個代碼示例不應該給那個(或)錯誤信息。你確定你的真實代碼沒有什麼不同嗎?你的文件在頂部是否包含'using System.Collections.Generic;'? –
您能否向我們展示產生錯誤的* exact *代碼:'無效表達式項'返回'' –
Acutally第一個錯誤解決了抱歉。 –