通过get set属性传递字符串 [英] To pass a string through get set property

查看:85
本文介绍了通过get set属性传递字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  public   class  RECORD 
{
public Field FD;
public RECORD()
{
Field f = new 字段();
f.identifier = ;
}
}
public class 字段
{
public string identifier { get ; set ;}

}
public class main()
{
string a = 某些值;
}



我必须将此字符串传递给标识符并将其显示在其他类中,例如类显示。我不应该直接从main访问标识符但必须通过课程RECORD访问。

请帮助!

解决方案

试着这样看:

  public   class  RECORD 
{
public 字段FD { get ; set ; }
public RECORD()
{
FD = new 字段();
FD.identifier = ;
}
}
public class 字段
{
public string identifier { get ; set ; }
}
public class main
{
private string a = 某个值;
public main()
{
RECORD r = new RECORD ();
r.FD.identifier = a;
}
}





删除局部变量声明屏蔽RECORD属性:谢谢Karthik ! - OriginalGriff [/ edit]


之前我见过这个:如何将值添加到另一个类的列表中 [ ^ ]

听起来像作业!

public class RECORD
    {
        public Field FD;
        public RECORD()
        {
  Field f=new Field();
  f.identifier="";
        }
    }
    public class Field
    {
        public string identifier { get;set;}

    }
  public class main()
  {
  string a="some value";
  }


I have to pass this string a to the identifier and display it in some other class for example class display .And i shouldnt access identifier directly from main class but have to access through the class RECORD.
please help!

解决方案

Try looking at it like this:

public class RECORD
     {
     public Field FD { get; set; }
     public RECORD()
         {
         FD = new Field();
         FD.identifier = "";
         }
     }
 public class Field
     {
     public string identifier { get; set; }
     }
 public class main
     {
     private string a = "some value";
     public main()
         {
         RECORD r = new RECORD();
         r.FD.identifier = a;
         }
     }



[edit]Removed local variable declaration masking RECORD property: Thanks Karthik! - OriginalGriff[/edit]


I have seen this before: How to add the values to the list from another class[^]
Sounds like homework!


这篇关于通过get set属性传递字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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