471,355 Members | 1,618 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,355 software developers and data experts.

Class design ToString

rc
is there anyway of creating a class so that when it is used as the object
directly it does the toSting implementation
ie
public class recordID
private mid as string
public overloads function Tostring as string
retrun mid
end function
end class
so if i was using recorid anywhere then i dont get unable to convert to
string error
Jul 21 '05 #1
3 1097
What you want is not available in VB.NET for VS2003, you need to overload the
"+" operation and the Cast operation which will be available in VS2005.

"rc" wrote:
is there anyway of creating a class so that when it is used as the object
directly it does the toSting implementation
ie
public class recordID
private mid as string
public overloads function Tostring as string
retrun mid
end function
end class
so if i was using recorid anywhere then i dont get unable to convert to
string error

Jul 21 '05 #2
On Fri, 15 Apr 2005 10:04:02 -0700, "Jorge Matos"
<matos_jorge(NOSPAM)@hotmail.com> wrote:

You mean you can't do this in VB.NET?:

public override string ToString()
{
return TheStringYouWantToReturn;
}
What you want is not available in VB.NET for VS2003, you need to overload the
"+" operation and the Cast operation which will be available in VS2005.

"rc" wrote:
is there anyway of creating a class so that when it is used as the object
directly it does the toSting implementation
ie
public class recordID
private mid as string
public overloads function Tostring as string
retrun mid
end function
end class
so if i was using recorid anywhere then i dont get unable to convert to
string error


Otis Mukinfus
http://www.otismukinfus.com
Jul 21 '05 #3
Otis,

Overriding methods is different from overloading operators, you can override
methods in VB.NET if you mark the method as Overrideable, but you cannot
override an operator such as "+" or "-", at least not until VS2005 is
released. Please refer to the following article for more info:

http://msdn.microsoft.com/library/de...ml/vs03h12.asp

"Otis Mukinfus" wrote:
On Fri, 15 Apr 2005 10:04:02 -0700, "Jorge Matos"
<matos_jorge(NOSPAM)@hotmail.com> wrote:

You mean you can't do this in VB.NET?:

public override string ToString()
{
return TheStringYouWantToReturn;
}
What you want is not available in VB.NET for VS2003, you need to overload the
"+" operation and the Cast operation which will be available in VS2005.

"rc" wrote:
is there anyway of creating a class so that when it is used as the object
directly it does the toSting implementation
ie
public class recordID
private mid as string
public overloads function Tostring as string
retrun mid
end function
end class
so if i was using recorid anywhere then i dont get unable to convert to
string error


Otis Mukinfus
http://www.otismukinfus.com

Jul 21 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

9 posts views Thread by David A. Osborn | last post: by
3 posts views Thread by Trammel | last post: by
2 posts views Thread by rc | last post: by
21 posts views Thread by phpCodeHead | last post: by
reply views Thread by XIAOLAOHU | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.