Frage

I have this simple class:

 public class Person
    {
        public int Id { get; set; }
        public string Name { get; set; }
        public int Age { get; set; }
        public int[] friends = new int[100];
    }

Then I create Ienumerable like this :

 IEnumerable<Person> lstPerson = ParallelEnumerable.Range(a, b).Select(f => new Person
            {
                Id = ...,
                Name =...,
                Age = ...,
                friends = ParallelEnumerable.Range(0, 100).ToArray()
            });

But running Monitor , you can see the the array is not serialized :

enter image description here

Related info :

this is how I actually insert to Redis :

   using (IRedisClient redisClient = new RedisClient(host))
            {
                IRedisTypedClient<Person> phones = redisClient.As<Person>();
                foreach (var element in lstPerson)
                {
                      phones.SetEntry("urn:user>" + element.Id, element);
                }
            }

Question :

What am I doing wrong ? why the array is not serialized and HOw can I make it to be included ?

War es hilfreich?

Lösung

Your friends is a field, not a property.

public class Person
{
    public int Id { get; set; }
    public string Name { get; set; }
    public int Age { get; set; }
  //public int[] friends = new int[100];
    public int[] Friends {get; set; }
}

since you fill it later with a ToArray() you don't really need to initialize it. When you still want to, use a constructor or write the long form of the property.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top