为什么我的列表不会增加?

时间:2022-12-08 07:18:43

my client returns an object and I want to store that object to a list of type of the object. I'm debugging and using the default windows client but while I am adding an object watching my list at the breakpoint only shows the latest object I passed.

我的客户端返回一个对象,我想将该对象存储到该对象的类型列表中。我正在调试并使用默认的Windows客户端,但是当我在断点处添加一个观察我的列表的对象时,只显示我传递的最新对象。

List<CompositeType> data= new List<CompositeType>();

    public void fromClient(CompositeType composite)
    {
        if (composite == null)
        {
            throw new ArgumentNullException("composite");
        }
        else
        {
            data.Add(composite);            
        }       
    }

This is in my IService:

这是我的IService:

[ServiceContract]
public interface IService
{
    [OperationContract]
    void fromClient(CompositeType composite);       
}

[DataContract]
public class CompositeType
{
    private string name;
    private float cpuUsage;
    private float ramAvailable;

    [DataMember]
    public string nameR
    {
        get { return name; }
        set { name= value; }
    }

    [DataMember]
    public float cpuUsageR
    {
        get { return cpuUsage; }
        set { cpuUsage = value; }
    }

    [DataMember]
    public float ramAvailableR
    {
        get { return ramAvailable; }
        set { ramAvailable = value; }
    }
}

1 个解决方案

#1


0  

please make your List data= new List(); as

请列出您的List data = new List();如

static List data= new List();

static List data = new List();

As previously (without static) it was generated when client calling it.. now it will preserve the state and you can add any number of objects you want to.

如前所述(没有静态)它是在客户端调用时生成的..现在它将保留状态,您可以添加任意数量的对象。

#1


0  

please make your List data= new List(); as

请列出您的List data = new List();如

static List data= new List();

static List data = new List();

As previously (without static) it was generated when client calling it.. now it will preserve the state and you can add any number of objects you want to.

如前所述(没有静态)它是在客户端调用时生成的..现在它将保留状态,您可以添加任意数量的对象。