Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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:

 

 

MyStructure.Name.MYOWNMETHOD1
MyStructure.Value.MYOWNMETHOD2

 

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

 

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

  • Administrators
Posted

I'm not really understanding what you are trying to do? I can't see exactly what the connection between

MyStructure.Value.MYOWNMETHOD2

and

MyStructure.Name = MYOWNMETHOD1("Hello")

is.

 

 

Could you give an example of what you are after?

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Posted

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

Posted

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 :)

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...