Click here to Skip to main content
15,897,371 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
public class Record
   {

        public List<Fie> Field = new List<Fie>();

}

SQL
public class Fie
   {       
public string Byt { get; set; }
public string Mon(string a)
             {
           string b=a;
           return a;      
 }
  }




I am getting a string in function Mon. Then I have to send that value to Public string Byt. After that I have to add the Byt in the list Field. I dont know how to do. Please post the answer. Thanks in Advance.
Posted
Comments
johannesnestler 23-Jan-14 5:12am    
so you list should contain the strings from Byt? (recommendation: use better names for your protperties and classes, time of 8char boundary is long over...). But your list is defined to hold Fie - Objects, not strings. So I think you have to step back, check your requriment and implement your class accordingly (don't use public variables, expose the list as property of a record. If you still have Problems I can give you an example - but at this Moment I don't understand what you want (and I can't deduce it from your naming, Record Ok, Field? not Fields? but then there are no Field objects the are called Fie? - you see what I mean?)

 
Share this answer
 
You can't add it to the list from within the Fie class - it doesn't (and definitely shouldn't) know even of the existence of the List of Fie instances so it can't access it in any way.

To add a new instance of Fie to your list is simple:
C#
public class Record
   {
   public List<Fie> Field = new List<Fie>();
   void AddIt(string s)
      {
      Field.Add(new Fie(s));
      }
   }

But it is also considered poor practice to publicly expose your fields directly - you should use a property instead (and possibly return a copy of the list instead of the actual list itself).
 
Share this answer
 

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