Click here to Skip to main content
15,897,891 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
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!
Posted
Updated 22-Jan-14 23:57pm
v2

Try looking at it like this:
C#
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]
 
Share this answer
 
v2
Comments
Maciej Los 23-Jan-14 6:08am    
+5!
Karthik_Mahalingam 23-Jan-14 8:59am    
5 +
Hi Griff

you need to change it Field FD = new Field();
as
FD = new Field();
else it will throw a null reference error.
OriginalGriff 23-Jan-14 10:56am    
Yep - c***-up on my part! :O
Karthik_Mahalingam 23-Jan-14 10:58am    
perfect :)
I have seen this before: How to add the values to the list from another class[^]
Sounds like homework!
 
Share this answer
 
Comments
Member 10543828 23-Jan-14 6:24am    
I think you didn't understand my question , gothrough once.I know how to add string to a list and I don't need that. my problem is string value is not passing to FD.identifier. I tried to display it inside set field its working.. but when I try it outside class I couldn't.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900