From: eBob.com on 20 Apr 2010 23:55 I implemented as class like this ... Public Class ComboxChoice Public ChoiceText As String Public LastUsed As Date Public UsedCount As Integer 'to be serializable we have to have a parameterless constructor Sub New() End Sub Sub New(ByRef Choice As String, ByRef LastUsed As Date, _ ByVal UsedCount As Integer) Me.ChoiceText = Choice Me.LastUsed = LastUsed Me.UsedCount = UsedCount End Sub Public Shadows ReadOnly Property ToString() As String Get Return Me.ChoiceText End Get End Property 'Public Overrides Function tostring() As String ' Return ChoiceText 'End Function End Class .... and I don't know what I was thinking when I made ToString a property rather than a function. BUT this ... MsgBox(New ComboxChoice("1st choice", DateTime.Now, 1).ToString) .... gave the expected result, i.e. "1st choice", while this ... cbx1.Items.AddRange(New Object() {New ComboxChoice("1st choice", DateTime.Now, 1), _ New ComboxChoice("2nd choice", DateTime.Now, 1)}) .... (where cbx1 is a ComboBox) does not - i.e. the items in the combobox do not appear as "1st choice" and "2nd choice". I understand that ComboBox is seeing the items as having a type of Object while in the MsgBox statement ToString is clearly a member of ComboxChoice. But what kind of invocation is ComboBox doing which manages to get the Object .ToString function rather than my objects ToString property? Isn't "Shadows" supposed to completely hide any ToString member in Object? Thanks, Bob
From: Tom Shelton on 21 Apr 2010 01:00 On 2010-04-21, eBob.com <eBob.com(a)totallybogus.com> wrote: > I implemented as class like this ... > > Public Class ComboxChoice > Public ChoiceText As String > Public LastUsed As Date > Public UsedCount As Integer > 'to be serializable we have to have a parameterless constructor > Sub New() > End Sub > Sub New(ByRef Choice As String, ByRef LastUsed As Date, _ > ByVal UsedCount As Integer) > Me.ChoiceText = Choice > Me.LastUsed = LastUsed > Me.UsedCount = UsedCount > End Sub > > Public Shadows ReadOnly Property ToString() As String > Get > Return Me.ChoiceText > End Get > End Property > > 'Public Overrides Function tostring() As String > ' Return ChoiceText > 'End Function > End Class > > ... and I don't know what I was thinking when I made ToString a property > rather than a function. BUT this ... > > MsgBox(New ComboxChoice("1st choice", DateTime.Now, 1).ToString) > > ... gave the expected result, i.e. "1st choice", while this ... > > cbx1.Items.AddRange(New Object() {New ComboxChoice("1st choice", > DateTime.Now, 1), _ > New ComboxChoice("2nd choice", > DateTime.Now, 1)}) > > ... (where cbx1 is a ComboBox) does not - i.e. the items in the combobox do > not appear as "1st choice" and "2nd choice". I understand that ComboBox is > seeing the items as having a type of Object while in the MsgBox statement > ToString is clearly a member of ComboxChoice. But what kind of invocation > is ComboBox doing which manages to get the Object .ToString function rather > than my objects ToString property? Isn't "Shadows" supposed to completely > hide any ToString member in Object? > > Thanks, Bob > The default behavior is to call Object.ToString(). You have not overriden ..ToString - but have shadowed it's implementation. So, the default object implmentation will be used. Shadows only hides the parent implementation from your descendants. -- Tom Shelton
From: eBob.com on 21 Apr 2010 13:05 "Tom Shelton" <tom_shelton(a)comcastXXXXXXX.net> wrote in message news:OCWdD%23Q4KHA.4804(a)TK2MSFTNGP04.phx.gbl... > On 2010-04-21, eBob.com <eBob.com(a)totallybogus.com> wrote: >> I implemented as class like this ... >> >> Public Class ComboxChoice >> Public ChoiceText As String >> Public LastUsed As Date >> Public UsedCount As Integer >> 'to be serializable we have to have a parameterless constructor >> Sub New() >> End Sub >> Sub New(ByRef Choice As String, ByRef LastUsed As Date, _ >> ByVal UsedCount As Integer) >> Me.ChoiceText = Choice >> Me.LastUsed = LastUsed >> Me.UsedCount = UsedCount >> End Sub >> >> Public Shadows ReadOnly Property ToString() As String >> Get >> Return Me.ChoiceText >> End Get >> End Property >> >> 'Public Overrides Function tostring() As String >> ' Return ChoiceText >> 'End Function >> End Class >> >> ... and I don't know what I was thinking when I made ToString a property >> rather than a function. BUT this ... >> >> MsgBox(New ComboxChoice("1st choice", DateTime.Now, 1).ToString) >> >> ... gave the expected result, i.e. "1st choice", while this ... >> >> cbx1.Items.AddRange(New Object() {New ComboxChoice("1st choice", >> DateTime.Now, 1), _ >> New ComboxChoice("2nd choice", >> DateTime.Now, 1)}) >> >> ... (where cbx1 is a ComboBox) does not - i.e. the items in the combobox >> do >> not appear as "1st choice" and "2nd choice". I understand that ComboBox >> is >> seeing the items as having a type of Object while in the MsgBox statement >> ToString is clearly a member of ComboxChoice. But what kind of >> invocation >> is ComboBox doing which manages to get the Object .ToString function >> rather >> than my objects ToString property? Isn't "Shadows" supposed to >> completely >> hide any ToString member in Object? >> >> Thanks, Bob >> > > The default behavior is to call Object.ToString(). You have not overriden > .ToString - but have shadowed it's implementation. So, the default object > implmentation will be used. Shadows only hides the parent implementation > from > your descendants. > > -- > Tom Shelton Thank you Tom, I was confused about the meaning of "Shadows". That confusion came in part from a compiler/VS message! If my definition of the ToString property omits "Shadows" then I get the message: "property 'ToString' conflicts with function 'ToString' in the base class 'Object' and should be declared 'Shadows'". I would say that 'Shadows' in this case didn't really resolve the conflict, or at least permitted an ambiguity. Thanks again for your help, Bob
|
Pages: 1 Prev: Foreign Currency Exchange Rates Web service Next: MailMessage message size |