Advertisement
JayBeeOH

Fun With Classes

Apr 25th, 2017
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 2.64 KB | None | 0 0
  1. '------------------------------------------------------------------------------------------
  2. '           Notice of My Copyright and Intellectual Property Rights
  3. '
  4. ' Any intellectual property contained within the program by Joseph L. Bolen remains the
  5. ' intellectual property of the Joseph L. Bolen. This means that no person may distribute,
  6. ' publish or provide such intellectual property to any other person or entity for any
  7. ' reason, commercial or otherwise, without the express written permission of Joseph L. Bolen.
  8. '
  9. '                 Copyright © 2017. All rights reserved.
  10. '        All trademarks remain the property of their respective owners.
  11. '-------------------------------------------------------------------------------------------
  12. ' Program Name:   Fun With Classes
  13. '
  14. ' Author:         Joseph L. Bolen
  15. ' Date Created:   25 APR 2017
  16. '
  17. ' Description:    Simple demo to show a simple class using auto-implemented
  18. '                 properties; the use of a List(Of T) collection that is
  19. '                 loaded with an initialization list; the use of LINQ to
  20. '                 sort the collection; and, assigning the sorted collection
  21. '                 to a DataGridView for display.
  22. '
  23.  
  24. '                 Documentation is at:
  25. '                   App's Visual Basic .NET code is at https://pastebin.com/yNkKhxe0
  26. '                   Video tutorial at YouTube: http://www.youtube.com/user/bolenpresents
  27. '-------------------------------------------------------------------------------------------
  28. Public Class MainForm
  29.  
  30.     Private Sub MainForm_Load(sender As Object, e As EventArgs) _
  31.         Handles MyBase.Load
  32.  
  33.         ' Using a List(Of T) and an initialization list.
  34.         Dim people As New List(Of Person) From
  35.             {New Person With {.FirstName = "Joe", .LastName = "Bolen", .Gender = "M"},
  36.             New Person With {.FirstName = "Tim", .LastName = "Hamilton", .Gender = "M"},
  37.             New Person With {.FirstName = "Cathy", .LastName = "Cunningham", .Gender = "F"},
  38.             New Person With {.FirstName = "Sally", .LastName = "Peterson", .Gender = "F"},
  39.             New Person With {.FirstName = "Patrica", .LastName = "Adele", .Gender = "F"}}
  40.  
  41.         ' LINQ method to order by LastName, then FirstName.
  42.         Dim query = people.OrderBy(Function(p) p.LastName).ThenBy(Function(p) p.FirstName)
  43.  
  44.         ' Assign the query to the DataGridView's datasource
  45.         MyDGV.DataSource = query.ToList
  46.     End Sub
  47. End Class
  48.  
  49. ' Simple Auto-implemented properties of the Person class
  50. Public Class Person
  51.     Public Property FirstName As String
  52.     Public Property LastName As String
  53.     Public Property Gender As String
  54. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement