Use List to sort system. Draw. Point objects (VB. NET source code)

Source: Internet
Author: User

To sort the list of any objects, you must write a class to implement the icomparer (of T) interface and the compare method,

In this example, we use the list of system. Drawing. point as an example to write an upcomparerpoint class for storing the point set in the list."Y"Sort from small to large

Of course, you can write your own classes to sort your class objects. Here is an example for your reference.

The usage is as follows:

Dim Ppoints as new list (of point)

Use Ppoints. Add to add the point to be compared

Then Ppoints. Sort (New upcomparerpoint)

The point set in Ppoints is"Y"Sorted from small to large

imports system. drawing
'''


''' this class implements system. drawing. point compare method, which can be used to add a point to the list, perform sort
'''

'''
public class upcomparerpoint
implements icomparer (of point)
'''
''' implements the compare method for icomparer
'''
''' compared X objects
''' compared y objects
'''
'''
public function compare (byval X as system. drawing. point, byval y as system. drawing. point) as integer implements system. collections. generic. icomparer (of system. drawing. point ). compare
If X. y> = y. Y then
return 1
else
return-1
end if
end function
end class

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.