【发布时间】:2016-09-06 04:53:19
【问题描述】:
我有一个通用列表类,我想使用这个类中的方法 CorrectData()。 目前我已经在类 LoadListe 中实现了方法 CorrectData()。如果我将其放入通用列表中,则会收到编译器错误 CS1061。
怎么了?
谢谢 史蒂芬
using System.Collections.ObjectModel;
namespace WindowsFormsGenerics
{
/// <summary>Basisklasse für alle Elemente </summary>
public class Base
{
/// <summary> Elementname </summary>
public string Name { get; set; }
/// <summary> Beschreibung </summary>
public string Description { get; set; }
}
public class Knoten : Base { }
public class OneNodeElement : Base
{
/// <summary> KnotenOne des Elementes </summary>
public Knoten KnotenOne { get; set; }
/// <summary> Schaltzustand am KnotenOne </summary>
public bool SwitchOne { get; set; }
}
public class Load : OneNodeElement
{
public void CorrectData(){}
}
public sealed class LoadListe : Liste<Load>
{
public void CorrectData()
{
foreach (Load item in this)
{
item.CorrectData();
}
}
}
public abstract class Liste<T> : Collection<T> where T : Base
{
public T GetItem(string searchsString, string parameter = "NAME")
{
return null;
}
public void CorrectData()
{
foreach (T item in this)
{
item.CorrectData();
}
}
}
}
【问题讨论】:
-
是否也很难给出错误信息?并指出你在哪一行得到了错误。你隐藏我们已经知道的信息是在浪费我们的时间!