我正在使用PHP代码,并且我没有太多的C#经验,我修改了我的代码很多,但仍然遇到错误“字段初始值设定项不能引用非静态字段,方法或属性“在行号为什么它总是发生并且如何解决它?C#错误:字段初始值设定项不能引用非静态字段方法或属性
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Finisar.SQLite;
namespace Stemmer
{
class ValueObj
{
public void postfix(string table)
{
SQLiteConnection sqlite_conn;
SQLiteCommand sqlite_cmd;
SQLiteDataReader sqlite_datareader;
sqlite_conn = new SQLiteConnection("Data Source=database.db;Version=3;New=False;Compress=True;");
sqlite_conn.Open();
sqlite_cmd = sqlite_conn.CreateCommand();
sqlite_cmd.CommandText = "SELECT * FROM " + table;
sqlite_datareader = sqlite_cmd.ExecuteReader();
List<string> list = new List<string>();
while (sqlite_datareader.Read())
{
list.Add(sqlite_datareader.GetString(1));
}
return list.ToArray(); // returns void, a return keyword must not be followed by an object expression
}
public string[] postfixList = postfix("postfixList"); // A field initializer cannot reference the non-static field, method, or property
}
}
哪里是第34行? – Stralos
public string [] postfixList = postfix(“postfixList”); –
C#不是PHP。它实际上很锋利。 –