Use the sort method of list

Source: Internet
Author: User
  1. Problem Source
    Openflashchart is used for icons over the past two days, so it has a DLL file, which can easily generate JSON data in the background and return it to the foreground.
    In the process of use, I have such a requirement that the point set on the line chart isList <linedotvalue>Set,LinedotvalueThe value attribute in the object indicates the size of the value. What should I do if I want to sort the set by the value?
  2. General Solution
    When you see this problem, you can generally think of using the sort method of list. The following forms are generally used:
    A) LetLinedotvalueClass implementationIcomparableInterfaceCompareto ()Method, inComparetoMethod. Then directly callSort ()Method
    B) Don't want to destroyLinedotvalueClass, then customize a comparatorLinedotvalueComparer, ImplementationIcomparer <linedotvalue>OfCompare ()Method, and then callSort (linedotvaluecomparer)
    C) write by yourselfAlgorithmSort ......
  3. My solution
    Unfortunately, I do not like the above methods, because I have referenced a ready-made DLL file and do not want to modify the source file, so Solution A is not applicable. This sorting is only used once in this place. If you do not want to write a comparator, Method B will be discarded. C doesn't need to be said ......
    Jquery users must be familiar with this method.
    1$ ('# Id'). Click (Function(){
    2//Code
    3});

    Can C # Be implemented in a similar way?
    The answer is yes. If you are using a vs2008 or later version, congratulations, whether you are framework2.0 or 3.5, you can use a Lamda expression.

     
    List <linedotvalue> values =NewList <linedotvalue> ();
    //Fill set
    Values. Sort (x, y) => X. value> Y. value? -1:0);

    If it is earlier than vs2005, you can use the delegate

    Values. Sort (Delegate(Linedotvalue X, linedotvalue y)
    {
    ReturnX. value> Y. value? -1:0;
    });

    OK.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.