我有两个类GenericNameValue,SpecificNameValue并继承自GenericNameValue.
我有一个接受参数的函数List<GenericNameValue>。我希望能够通过List<SpecificNameValue>。该函数对SpecificNameValue.
最好的方法是什么?
public class GenericNameValue
{
public string FieldName{get;set;}
public string FieldValue{get;set;}
}
public class SpecificNameValue : GenericNameValue
{
public string SpecificFieldValue{ get; set; }
}
public static UtitlityClass
{
public string CombineAllFields(List<GenericNameValue> mylist)
{
//.... do stuff with each item
}
}
//......Example of calling the utilityclass
string stuff = UtilityClass.CombineAllFields(mySpecificNameValue);
那么我是否缺少特定的语法?我应该使用像 Abstracts 这样的不同的东西吗?
抱歉,这只是让我头疼一阵子的事情之一,我想要一个优雅的解决方案。