| | |
using generic procedures
Please support our VB.NET advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: May 2008
Posts: 3
Reputation:
Solved Threads: 0
VB.NET Syntax (Toggle Plain Text)
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim x As Int16, y As Int16 x = CInt(TextBox1.Text) y = CInt(TextBox2.Text) add(10, 20) End Sub Private Sub add(Of T)(ByVal x As T, ByVal y As T) Dim res As T res = x + y MsgBox(res) End Sub Private Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click Dim x As Double, y As Double x = CDbl(TextBox1.Text) y = CDbl(TextBox2.Text) add(4.5, 5.6) End Sub
This is the code i used but there is an error " Operator + not defined for datatype 'T' and 'T' ". what is wrong in this. thanks in advance
•
•
•
•
VB.NET Syntax (Toggle Plain Text)
Private Sub add(Of T)(ByVal x As T, ByVal y As T) Dim res As T res = x + y MsgBox(res) End Sub
"give only what u willing to receive "
•
•
Join Date: May 2008
Posts: 3
Reputation:
Solved Threads: 0
T is to accept any data type that we pass as the argument. that is the main advantage of generics in .net. the following code works fine, but doesnot allow the + opertor.
VB.NET Syntax (Toggle Plain Text)
Private Sub add(Of T)(ByVal x As T, ByVal y As T) 'Dim res As T 'res = x + y MsgBox("The values are " & x.ToString & ", " & y.ToString) End Sub
![]() |
Similar Threads
- Dot Net programmer wanted. Work from home. (Web Development Job Offers)
- VB.NET / VB6 Analyst Programmer X 2 - Manchester (Software Development Job Offers)
- Opportunity at Warner Bros. - Senior Web Developer, New Media (Web Development Job Offers)
- Dimensioning Strings (C#)
- Windows XP Plug N Play problem (Windows NT / 2000 / XP)
- Ginormous Problem With XP (Windows NT / 2000 / XP)
Other Threads in the VB.NET Forum
- Previous Thread: help in my linkin....
- Next Thread: help with time.....
| Thread Tools | Search this Thread |
.net .net2008 2008 access account advanced application array basic beginner browser button buttons center click code combo cuesent data database datagrid datagridview date datetimepicker designer dissertation dissertations dissertationtopic excel exists fade filter forms ftp generatetags html images input insert intel internet listview map mobile module monitor msaccess net number objects open panel passingparameters pdf picturebox picturebox2 port position print printing problem regex right-to-left save search searchvb.net select serial settings shutdown socket sqldatbase sqlserver survey table temperature textbox timer timespan transparency txttoxmlconverter update user usercontol vb vb.net vb.netformclosing()eventpictureboxmessagebox vba vbnet visual visualbasic visualbasic.net visualstudio.net visualstudio2008 web winforms wpf wrapingcode xml year





