2012-11-27 2 views
-3

objet 목록 (키, 이름)을 이름으로 주문할 수있는 방법을 알려주거나 가이드를 제공 할 수 있는지 궁금하지만 이름은 LocalizedText 형식이며 어쩌면 나는 그렇게 할 수 있습니다. 바보 같지만이 목록을 주문할 수 없습니다. 당신이 너무 List(Of Object)을 사용하고있는 경우는 같은 것이다 종류 - 2와 List()이 없을 수현지화 된 텍스트 목록을 주문하는 방법

//Objects definied on my class: 
    [DataMember] 
    public virtual Guid ComplaintPreventableStateId { get; set; } 
    [DataMember] 
    public virtual LocalizedText Name { get; set; } 


    //function that tries to get information: 
IList<ComplaintPreventableState> complaintPreventableList = new List<ComplaintPreventableState>(); 
     complaintPreventableList = (from c in ComplaintPreventableState.All select c).ToList(); 
    //Tried this two options:   
complaintPreventableList.OrderByDescending(h => h.Name); 
complaintPreventableList.OrderBy(h => h.Name); 
+0

일부 코드를 게시해야합니다. 당신이 가지고있는 어떤 것도 도움이 될 것입니다. 대답은 모두 가정에 근거하고 있지만 답변을 넣었습니다. – Darren

+0

내 대답을 다시 읽습니다 ... 업데이트 추가 중. 전에 말한 것을 다시 반복하십시오. 당신은 그 순서를 다시 자신에게 할당하지 않습니다. OrderBy를 호출하면 목록에서 .tolist()를 호출 할 때 사용할 메서드를 설정할 수 있습니다. 당신이 그것을 원한다면 당신은 그것을 저장해야합니다. – Darren

답변

0

난 당신이 예를 들어 KeyValuePair(Of Integer, String)의 목록을 가지고 있으리라 믿고있어.

그러면 Bob, Harry, John이되는 이름순으로 목록이 설정됩니다.

 complaintPreventableList = complaintPreventableList.OrderBy(h => h.Name).ToList(); 

공지 사항도 마지막에 호출 .ToList() : 여기에

 complaintPreventableList.OrderBy(h => h.Name); 

:

는 UPDATE

그래서, 예를 들어 코드를 사용하여이를 변경해야 .

이전 예에서와 같이; 순서가 지정된 목록을 다시 할당해야합니다.

+0

답해 주셔서 고맙습니다.하지만이 문제는 내 문제를 해결하지 못합니다. OrderBy와 OrderByDescending을 사용하지만 결과 순서는 변경되지 않습니다. – Joseph

+0

'list = list.OrderBy (Function (p) p.Value) .ToList()'위의주의 사항 - 새로운 순서로'list'를 설정하고 있습니다. 이것은 100 % 일하는 방법입니다. 작동하지 않는 경우 다른 문제가있어서 코드 – Darren

+0

을 게시해야합니다. 친구가 나에게이 옵션을 제공합니다. IList complaintPreventableList = new List (); complaintPreventableList.AddRange (ComplaintPreventableState.All.ToList(). OrderBy (k => k.Name.ToString())); – Joseph

관련 문제