VB.Net Tutorial/Class Module/Object Instance — различия между версиями

Материал из VB Эксперт
Перейти к: навигация, поиск
м (1 версия)
 
(нет различий)

Версия 16:40, 26 мая 2010

Create an object and call its method.

Module YourClassTest
   Sub Main()
      Dim obj As New YourClass()
      obj.DisplayMessage()
   End Sub 
End Module 
Public Class YourClass
   Public Sub DisplayMessage()
      Console.WriteLine("Welcome!")
   End Sub 
End Class
Welcome!

Sort objects in an array

Imports System.Collections
public class Test
  
   public Shared Sub Main
        Dim people(4) As Employee
        people(0) = New Employee("R", "S")
        people(1) = New Employee("S", "A")
        people(2) = New Employee("T", "P")
        people(3) = New Employee("H", "S")
        people(4) = New Employee("E", "C")
        " Sort.
        Array.Sort(people)
        For i As Integer = 0 To people.GetUpperBound(0)
            Console.WriteLine(people(i).ToString())
        Next i
   End Sub
   
End class
Public Class Employee
    Implements IComparable
    Public FirstName As String
    Public LastName As String
    Public Sub New(ByVal first_name As String, ByVal last_name As String)
        FirstName = first_name
        LastName = last_name
    End Sub
    Public Overrides Function ToString() As String
        Return LastName & ", " & FirstName
    End Function
    Public Function CompareTo(ByVal obj As Object) As Integer _
     Implements System.IComparable.rupareTo
        Dim other_Employee As Employee = DirectCast(obj, Employee)
        Return String.rupare(Me.ToString, other_Employee.ToString)
    End Function
End Class
A, S
C, E
P, T
S, H
S, R