a ordem do campo é importante na inicialização automática de tipos anônimos?
Eu tenho um cenário para criar a lista anônima a partir dos tipos anônimos, e consegui isso usando
public static List<T> MakeList<T>(T itemOftype)
{
List<T> newList = new List<T>();
return newList;
}
static void Main(string[] args)
{
//anonymos type
var xx = new
{
offsetname = x.offName,
RO = y.RO1
};
//anonymos list
var customlist = MakeList(xx);
//It throws an error because i have given the wrong order
customlist.Add(new { RO = y.RO2, offsetname = x.offName });
customlist.Add(new { RO = y.RO3, offsetname = x.offName });
//but this works
customlist.Add(new { offsetname = x.offName, RO = y.RO2 });
customlist.Add(new { offsetname = x.offName, RO = y.RO3 });
}
estas são as mensagens de erro
System.Collections.Generic.List.Add (AnonymousType # 1) 'possui alguns argumentos inválidos
Argumento '1': não é possível converter de 'AnonymousType # 2' para 'AnonymousType # 1'
Qual é a razão por trás disso?