| | |
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 |
"crystal .net .net2005 30minutes 2008 access add advanced application array assignment basic binary box button buttons center click code combo connectionstring convert cpu data database databasesearch datagrid datagridview design designer dissertation dissertations dissertationthesis dosconsolevb.net editvb.net employees excel exists firewall folder image images isnumericfuntioncall listview login map math memory mobile module msaccess mssqlbackend mysql navigate net number opacity pan peertopeervideostreaming picturebox picturebox2 port print printpreview record regex reports" reuse right-to-left save savedialog search serial socket sorting sqldatbase sqlserver storedprocedure string temp textbox timer txttoxmlconverter upload useraccounts usercontol usercontrol vb vb.net vb.netcode vb.nettoolboxvisualbasic2008sidebar vbnet vista visual visualbasic visualbasic.net visualstudio.net web wpf xml





