Method that behaves like ToString

Doggo120

Newcomer
Joined
Oct 7, 2011
Messages
23
Location
Colombia
Hi again and again and again!

I would like to have methods that behave like ToString:

Let's say I have a structure or class that has some properties like 'Name' and 'Value'. How would I implement some methods like this:


Code:
MyStructure.Name.MYOWNMETHOD1
MyStructure.Value.MYOWNMETHOD2

Is there a way to achieve this? I know I can do it this way:

Code:
MyStructure.Name = MYOWNMETHOD1("Hello")

But I was wondering if there's any way to do this like the first example.

Any ideas awesome guys? :D
 
I'm not really understanding what you are trying to do? I can't see exactly what the connection between
Code:
MyStructure.Value.MYOWNMETHOD2
and
Code:
MyStructure.Name = MYOWNMETHOD1("Hello")
is.


Could you give an example of what you are after?
 
Hi Plausibly, thank u for the response :)

Actually I found out what I was looking for: Extension Methods!!!

That way I can achiveve things like the one I posted before:

MyStructure.Name.MYOWNMETHOD1
 
haha, I wanted some specific structures and variables to have unique methods, for example:

Dim HappyVariable as Byte (I wanted to convert a byte variable into let's say, some kind of string depending on its value)

HappyVariable.ConvertToHappyString -> Here my extended methods come into work because I can convert any byte variable into what I want :)

I mentioned the ToString() method because it behaves like that, it appears on pretty much everything you declare :)
 
Back
Top