Serializing a WCF, IList, or List Collection? Does it matter?

Is there a preferred collection object when serializing to WCF? I am trying to decide between a List or an IList and am wondering if this matters?

+5
source share
1 answer

It does not matter in terms of serialization. There is no IList or List on Explorer . Both results will result in the same XML.

From MSDN :

All collections of lists of the same type are considered the same (unless they are configured using the CollectionDataContractAttribute attribute, as described later in this topic document). For example, the following data contracts are equivalent.

[DataContract(Name = "PurchaseOrder")]
public class PurchaseOrder1
{
    [DataMember]
    public string customerName;
    [DataMember]
    public Collection<Item> items;
    [DataMember]
    public string[] comments;
}

[DataContract(Name = "PurchaseOrder")]
public class PurchaseOrder2
{
    [DataMember]
    public string customerName;
    [DataMember]
    public List<Item> items;
    [DataMember]
    public BindingList<string> comments;
}
+10
source

All Articles