VB.Net Overloads的实例
代码如下:
乐博网lob.cn提示:调试环境为 vs2005 + windows2003 / windows2008 / xp / vista
Public Class OverloadsForm Dim mianji As OverFather
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click mianji = New OverFather Dim r As Single = CSng(InputBox("求圆面积,输入半径")) mianji.area1(r) End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click mianji = New OverFather Dim width As Single = CSng(InputBox("求矩形面积,输入长")) Dim Height As Single = CSng(InputBox("求矩形面积,输入宽")) mianji.area1(width, Height) End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click mianji = New OverFather Dim topbottom As Single = CSng(InputBox("求梯形面积,输入上底")) Dim downbottom As Single = CSng(InputBox("求梯形面积,输入下底")) Dim Height As Single = CSng(InputBox("求矩形面积,输入高")) mianji.area1(topbottom, downbottom, Height) End Sub End Class Class OverFather Inherits FatherClass Overloads Sub area1(ByVal r As Single) MessageBox.Show("乐博网提示:圆面积为:" & r ^ 2 * 3.14) End Sub Overloads Sub area1(ByVal width As Single, ByVal height As Single) MessageBox.Show("乐博网提示:矩形面积为:" & width * height) End Sub Overloads Sub area1(ByVal topbottom As Single, ByVal downbottom As Single, ByVal height As Single) MessageBox.Show("乐博网提示:矩形面积为:" & (topbottom + downbottom) * height / 2) End Sub End Class
|