如何在Record类中获取Field类的属性 [英] How to get the property of Field class in Record class

查看:169
本文介绍了如何在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.


更改构造函数(编译):

Change your constructor (so it compiles):
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;


感谢您给出答案......但我仍然无法得到它。你可以为此发布一些其他选项......
Thanks for giving answers... Still I am not able to get it. Can you please post some other options for this...


这篇关于如何在Record类中获取Field类的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆