jeudi 18 février 2016

Ordering of properties on an object [duplicate]

This question already has an answer here:

private string DoStuff(object result, StringBuilder returnBuilder)
{
    // get a list of all public properties and order by name 
    // so we can guarentee that the order of the headers and 
    // the results are the same
    foreach (var prop in result.GetType().GetProperties().OrderBy(x => x.Name))
    {
        //    do something cool
    }
}

My question is, without the OrderBy in the for loop am I guarenteed that the native order of the List will be the order the properties are declared in the object





Aucun commentaire:

Enregistrer un commentaire