我正在適應一個包含類的一些現有的C#代碼:吸氣特性定義,但沒有發現使用時
public class tagTLSEEKINFO
{
/* Disable variable visibility on debug. */
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private DateTime date;
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private string month;
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private string year;
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private int trunk;
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private int addr;
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private int subzone;
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private tagTLFILETYPE filetype;
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private string path;
public tagTLSEEKINFO()
{
Path = "";
}
public tagTLSEEKINFO(tagTLFILETYPE filetype)
{
FileType = filetype;
}
public tagTLSEEKINFO(tagTLFILETYPE filetype, string _path)
{
Month = "";
Year = "";
Trunk = Addr = Subzone = 0;
FileType = filetype;
Path = _path;
}
public tagTLSEEKINFO(DateTime date, tagTLFILETYPE filetype)
{
Date = date;
Month = date.Month.ToString("00");
Year = date.Year.ToString().Remove(0, 2);
Trunk = Addr = Subzone = 0;
FileType = filetype;
}
public tagTLSEEKINFO(string month, string year, tagTLFILETYPE filetype)
{
Date = new DateTime(Convert.ToInt16(year), Convert.ToInt16(month), 1);
Month = month;
Year = year;
Trunk = Addr = Subzone = 0;
FileType = filetype;
}
public tagTLSEEKINFO(DateTime date, int trunk, int addr, int subzone)
{
Date = date;
Month = date.Month.ToString("00");
Year = date.Year.ToString().Remove(0, 2);
Trunk = trunk;
Addr = addr;
Subzone = subzone;
FileType = tagTLFILETYPE.TRENDLOG;
}
public tagTLSEEKINFO(string month, string year, int trunk, int addr, int subzone)
{
Month = month;
Year = year;
Trunk = trunk;
Addr = addr;
Subzone = subzone;
FileType = tagTLFILETYPE.TRENDLOG;
}
public virtual DateTime Date { get { return date; } set { date = value; } }
public virtual string Month { get { return month; } set { month = value; } }
public string Year { get { return year; } set { year = value; } }
public int Trunk { get { return trunk; } set { trunk = value; } }
public int Addr { get { return addr; } set { addr = value; } }
public int Subzone { get { return subzone; } set { subzone = value; } }
public tagTLFILETYPE FileType { get { return filetype; } set { filetype = value; } }
public string Path { get { return path; } set { path = value; } }
}//end class
當我嘗試使用我所需要的屬性(日期),我得到這個錯誤:
Error CS1061 'tagTLSEEKINFO[]' does not contain a definition for 'Date' and no extension method 'Date' accepting a first argument of type 'tagTLSEEKINFO[]' could be found (are you missing a using directive or an assembly reference?) TrendLogFileViewer
你能告訴我們你在哪裏收到錯誤的行? – Allen
由於缺乏可靠地再現問題的良好[mcve],所以無法肯定地說。但根據錯誤消息,看起來你有一個'tagTLSEEKINFO'對象數組,並試圖從數組中檢索Date屬性值,而不是索引數組,並從數組的單個元素中檢索屬性值。你不能那樣做。找出你想從哪個元素獲取值,並使用合適的索引值來獲取該元素。 –