我有下面的代碼的問題:獲得一個「爲最佳重載的方法匹配......有一些無效參數」的錯誤消息
public class ClientGroupDetails
{
public DateTime Col2;
public String Col3;
public Int32 Col4;
public ClientGroupDetails(DateTime m_Col2, String m_Col3, Int32 m_Col4)
{
Col2 = m_Col2;
Col3 = m_Col3;
Col4 = m_Col4;
}
public ClientGroupDetails() { }
}
[WebMethod()]
public List<ClientGroupDetails> GetClientGroupDetails(string phrase)
{
var client_group_details = new List<ClientGroupDetails>();
using (connection = new SqlConnection(ConfigurationManager.AppSettings["connString"]))
{
using (command = new SqlCommand(@"select col2, col3, col4 from table1 where col1 = @strSearch", connection))
{
command.Parameters.Add("@strSearch", SqlDbType.VarChar, 255).Value = phrase;
connection.Open();
using (reader = command.ExecuteReader())
{
int Col2Index = reader.GetOrdinal("col2");
int Col3Index = reader.GetOrdinal("col3");
int Col4Index = reader.GetOrdinal("col4");
while (reader.Read())
{
client_group_details.Add(new ClientGroupDetails(
reader.IsDBNull(Col2Index) ? (Nullable<DateTime>)null : (Nullable<DateTime>)reader.GetDateTime(Col2Index),
reader.IsDBNull(Col3Index) ? null : reader.GetString(Col3Index),
reader.GetInt32(Col4Index)));
}
}
}
}
return client_group_details;
}
}
這是給我下面的錯誤:
Compiler Error Message: CS1502: The best overloaded method match for 'Conflicts.ClientGroupDetails.ClientGroupDetails(System.DateTime, string, int)' has some invalid arguments
Line 184: client_group_details.Add(new ClientGroupDetails(
(無聲無息地公開字段,帶'm_'前綴的參數等) – 2012-02-24 12:39:07
@Marc Grav呃,爲什麼? – oshirowanen 2012-02-24 13:00:58
公共領域從來都不是一個好主意,並且不會對屬性賦予任何幫助,從而使您能夠安全地稍後調整實現(並且完全不需要任何費用)。那麼'm_'告訴你,你還不知道?實際上,大多數人喜歡這樣的符號使用'm_'作爲**字段**,而不是參數 – 2012-02-24 13:17:03