本文介绍了如何在Record类中获取Field类的属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
public class Record
{
public List<field> Field_list = new List<field>();
public Record()
{
Field h = new Field();
h.StructureField_Identifier = "";
Field.Add(h);
}
}
public class Field
{
public string StructureField_Identifier { get; set; }
}
//我在公共字符串StructureField_Identifier获取值。我必须在Field_list列表中获取该值。所以我使用的是Constructor Record()和Field实例。但我无法得到它。如何在Record类中获取Field类的属性
//I am getting the value at public string StructureField_Identifier. I have to get that value in the list "Field_list". So I am using Constructor Record() and Field instance. But I am not able to get it. How to get the property of Field class in Record class
推荐答案
public class Record
{
public List<Field> Field_list = new List<Field>();
public Record()
{
//insted of this
Field h = new Field();
h.StructureField_Identifier = "";
//replace this line
Field_list.Add(new Field { StructureField_Identifier = "" });
}
}
public class Field
{
public string StructureField_Identifier { get; set; }
}
in
in
Field_list
你可以得到一个属性值。
you can get a value of property.
public Record()
{
Field h = new Field();
h.StructureField_Identifier = "";
Field_list.Add(h);
}
然后尝试:
Then try:
Record r = new Record();
Field f = r.Field_list[0];
String s = f.StructureField_Identifier;
这篇关于如何在Record类中获取Field类的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!