المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Get/Set for List in C#



C# Programming
05-21-2009, 05:10 PM
Hi guys. I got a problem I cant find solution to anywhere over the internet..I might have missed something in my logic.

class DefComparing:DefCompareProperty
{
public void DefCompare()
{
List def_compare = new List();
********doing something to the list here******
DefCompareProperty df = new DefCompareProperty();
foreach (string s in def_compare)
{
df.SetDefComp(s);
}
}
}

Then I want to use the def_compare list in another class.

public class Aliniere
{
public List def_compare = new List();
public void Aliniate()
{
******doing some operations here****
DefComparing newdefcomp = new DefComparing();
newdefcomp.DefCompare();
def_compare = df.GetDefComp(); //Trying to get the list from that other class


What I tried to do is make Set/Get properties for the list.


class DefCompareProperty
{
private List lst = new List();

public List GetDefComp()
{
return lst;
}
public void SetDefComp(string members)
{
lst.Add(members);
}
}


So the problem is I cant get the list from class1 to class 2 using class3(set/get). I am doing some mistake. Can you help?

Thanks in advance