Witam
Podczas nauki podstaw visual basica natrafiłem na następujący kod, którego nie mogę zrozumieć:
Public Class Form1
Dim MaxArgumentKwadrat As Integer = Math.Sqrt(Integer.MaxValue)
Private Function Kwadrat(argument As Integer) As Integer
Dim wartosc As Integer
If argument > MaxArgumentKwadrat Then
Throw New Exception("Argument metody kwadrat ma zbyt dużą wartość")
End If
wartosc = argument * argument
Return wartosc
End Function
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Try
Dim x As Integer = 4
Dim y As Integer = Kwadrat(x)
y = Kwadrat(y)
Dim sy As String = y.ToString()
MessageBox.Show("Wynik: " & sy)
Catch ex As Exception
MessageBox.Show("Błąd: " & ex.Message, "Przechwycony wyjątek w metodzie Button_Click",
MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
MessageBox.Show(MaxArgumentKwadrat)
End Sub
End Class
Druga linia - ja to rozumiem w następujący sposób - przypisujemy do zmiennej typu integer maksymalną wartość integer podniesioną do kwadratu... ale jak możemy przypisać do zmiennej integer wartość która nie mieści się w jej zakresie? Przecież ona jest podniesiona do kwadratu.
I druga rzecz:
If argument < MaxArgumentKwadrat
przecież żeby to miało sens powinien być użyty operator ">"
przykład z tej książki
http://helion.pl/ksiazki/visual-basic-net-w-praktyce-blyskawiczne-tworzenie-aplikacji-jacek-matulewski,vbnepr.htm