SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Hybrid View

  1. #1
    SitePoint Enthusiast
    Join Date
    Nov 2006
    Posts
    80
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    2 constuctors with same number of parameters

    Hi All
    I am trying to create a custom class to hold data from a database with the following code

    Public Class NewsObject

    Public Property articleID() As Integer
    Public Property articleTitle() As String
    Public Property articleBody() As String

    Public Sub New()

    End Sub

    Public Sub New(ByVal articleid As Integer, ByVal atricletitle As String)
    Me.articleID = articleid
    Me.articleTitle = atricletitle
    End Sub

    Public Sub New(ByVal atricletitle As String, ByVal articlebody As String)
    Me.articleTitle = atricletitle
    Me.articleBody = articlebody
    End Sub

    Public Sub New(ByVal articleid As Integer, ByVal atricletitle As String, ByVal articlebody As String)
    Me.articleID = articleid
    Me.articleTitle = atricletitle
    Me.articleBody = articlebody
    End Sub

    End Class


    When I try to create an instance of this object I cannot use the 2nd or 3rd constructor
    throws an overload resolution exception. I know both constructors have the same number of parameters
    but they are of different data types so I thought this was allowed

    Can anyone shed any light on this

    Many Thanks

  2. #2
    SitePoint Author silver trophybronze trophy
    wwb_99's Avatar
    Join Date
    May 2003
    Location
    Washington, DC
    Posts
    10,623
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)
    It probably is coming from the data types you are using to call things -- ie if you are passing in the result of a textbox that might look like an integer but it actually is a string insofar as the CLR goes. Anyhow, try explicit casts to see if that helps.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •