Mike_R Posted December 5, 2004 Posted December 5, 2004 Hi guys, I'm trying to make a very simple 'Convert' class. The idea is to Inherit & extend the System.Convert class, but, technically, that class is not Inheritable... Anyway, I'll "inherit" this functionality by using System.Convert when necessary... My current problem is far simpler, I can't even get on first base! My code is as follows:Friend Class xoConvert Friend Function ToString(ByVal TheObject As Object) As String End Function End Class The result of the above is a squiggly line below the word 'ToString' and the error message reads:Function 'ToString' shadows an overloadable member declared in the base class 'Object'. If you want to overload the base method, this method must be declared 'Overloads'. I was puzzled by this, esp. given that the same code in C# appears to be fine: public class xoConvert { public String ToString(Object TheObject) { } } Any ideas with what I'm doing wrong here. I'm neither trying to Overload nor Shadow anything. Heck, this Class, as constructed so far, isn't even Inheriting anything... Thanks in advance :), Mike Quote Posting Guidelines Avatar by Lebb
Joe Mamma Posted December 5, 2004 Posted December 5, 2004 I am assumming you want a static methid, similar to the other converts. . . [/color] [color=black]Public [/color][/color][/size][color=black][size=2]Class[/size][size=2] CustomConvert[/size][/color] [color=black][size=2]Public [/size][size=2]Overloads [/size][size=2]Shared [/size][size=2]Function[/size][size=2] ToString([/size][size=2]ByVal[/size][size=2] anObject [/size][size=2]As[/size][size=2]Object[/size][size=2]) [/size][size=2]As[/size][size=2]String[/size][/color] [color=black][color=black][size=2][/size][/color][/color] [color=black][color=black][size=2]End [/size][/color][/color][color=black][size=2]Function Frankly, for ToString, I would redefine ToString in your projects classes Quote Joe Mamma Amendment 4: The right of the people to be secure in their persons, houses, papers, and effects, against unreasonable searches and seizures, shall not be violated, and no warrants shall issue, but upon probable cause, supported by oath or affirmation, and particularly describing the place to be searched, and the persons or things to be seized. Amendment 9: The enumeration in the Constitution, of certain rights, shall not be construed to deny or disparage others retained by the people.
Mike_R Posted December 5, 2004 Author Posted December 5, 2004 Thanks Joe, I really appreciate it... (1) Yes, it is to be Static ("Shared"), but in my confusion over the compiler complaining/requiring that I use the 'Overloads' keyword, I tried making changes, including (a) making it a Friend Method and (b) removing 'Shared'. (No real reason for the latter, but I was willing to try anything!) (2) Ok, so you used 'Overloads' and that seems natural to you... Can you explain the mentality here? This Class is within it's own NameSpace; there should be no conflicts, I would think, and so no need for Overloads? Clearly I'm not quite understanding something (basic!) here. Could you help me out? (3) My goal for this (currently), is to create a method that can convert an Array to print out it's contents. Something that would work like this:Dim MyArray(,) As Integer = {{1, 2, 3,},{3, 4, 5}} CustomConvert.ToString(MyArray) ' <-- Returns: "{{1, 2, 3,},{3, 4, 5}}" The logic of going through this is fairly easy (and I've done it for VB6 before), do you know if I'm re-inventing the wheel here? That is, is there a .Net method that already has tis capablity? Much thanks for help on any of the above! :) Mik Quote Posting Guidelines Avatar by Lebb
Joe Mamma Posted December 5, 2004 Posted December 5, 2004 everything derives from the class Object Object has a Virtual Method ToString() the default ToString() returns, I believe the name of the class. given: Public Class MyClass end class then dim mc as MyClass = New MyClass() dim s as string = MyClass.ToString() s is now equal to "MyClass" in order to get different behavior, you must overload/override Quote Joe Mamma Amendment 4: The right of the people to be secure in their persons, houses, papers, and effects, against unreasonable searches and seizures, shall not be violated, and no warrants shall issue, but upon probable cause, supported by oath or affirmation, and particularly describing the place to be searched, and the persons or things to be seized. Amendment 9: The enumeration in the Constitution, of certain rights, shall not be construed to deny or disparage others retained by the people.
Mike_R Posted December 5, 2004 Author Posted December 5, 2004 I see.. I'm "implicitly" inheriting from the Object class. I had not thought about that. Thanks very much! Huh, this is odd... 'Object.ToString' does not show up under IntelliSense/AutoComplete within VB.Net, but it can be called. And it does show up as a public memeber within the Object Browser. Strange, eh? How can it be Public and yet not show up under IntelliSense? Quote Posting Guidelines Avatar by Lebb
Administrators PlausiblyDamp Posted December 8, 2004 Administrators Posted December 8, 2004 By default VB 'hides' certain things from the intellisense because they are 'advanced', if you lok under the options you can get it to display everything. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Mike_R Posted December 8, 2004 Author Posted December 8, 2004 Ok, I found it where you said it would be. Thank you very much. :) I can see why they did this and I don't mind them hiding them. It shortens the IntelliSense list when using my own Classes, reducing the clutter. However, in this case, that they considered '.ToString' to be "Advanced" is a little silly, eh? Anyway, I thank you much for the info, it's a big help. Quote Posting Guidelines Avatar by Lebb
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.