我有我的asp.net mvc的類中的以下方法: -對象引用需要非靜態字段,方法或屬性
public class Crud
{
Repository repository = new Repository();
List<string> activeTech = repository.getAll().ToList();
,但我得到以下異常: -
Error 1 An object reference is required for the non-static field, method, or property
但如果添加靜態到我的代碼如下,異常將被刪除: -
public class Crud {
static Repository repository = new Repository();
List<string> activeTech = repository.getAll().ToList();
所以CA ñ任何人的建議,請這?
謝謝
當然,你會希望你的第二個陳述在方法中? –