0

この選択を vehicle.DateRegistered でソートしようとしていますが、本当に混乱していて、何も機能していないようです。どんな助けでも大歓迎です。

 var lookupValues = vehicles
            .Select(vehicle =>
                new LookupValue()
                {
                    Id = vehicle.Id,
                    Description = vehicle.RegistrationNumber + " " +vehicle.DateRegistered.ToString("dd/mm/yyyy"),
                    Data = Json.GetString(vehicle),
                    Active = true
                });
        return lookupValues;

ありがとうオースティン

4

3 に答える 3

3

OrderBy拡張メソッドを使用します。

var lookupValues = vehicles.OrderBy(v => v.DateRegistered).Select(.....);
于 2012-09-28T12:20:05.570 に答える
1
var lookupValues = vehicles
        .OrderBy(vehicle => vehicle.DateRegistered)
        .Select(vehicle =>
            new LookupValue()
            {
                Id = vehicle.Id,
                Description = vehicle.RegistrationNumber + " " +vehicle.DateRegistered.ToString("dd/mm/yyyy"),
                Data = Json.GetString(vehicle),
                Active = true
            });
    return lookupValues;
于 2012-09-28T12:24:57.040 に答える
1

You can try with this code - based on OrderBy Linq operator

lookupValues.OrderBy(a=> a.DateRegistered);

Nota : Add DateRegistered in your selector

Or also you can use this

var lookupValues = vehicles

                .OrderBy(a => a.DateRegistered) 
                .Select(vehicle =>
                new LookupValue()
                {
                    Id = vehicle.Id,
                    Description = vehicle.RegistrationNumber + " " +vehicle.DateRegistered.ToString("dd/mm/yyyy"),
                    Data = Json.GetString(vehicle),
                    Active = true
                });
        return lookupValues;

Nota : you define direction of order : descending or ascending

于 2012-09-28T12:22:14.233 に答える