Doggo120 Posted May 30, 2012 Posted May 30, 2012 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 Quote
Administrators PlausiblyDamp Posted May 30, 2012 Administrators Posted May 30, 2012 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? Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Doggo120 Posted May 31, 2012 Author Posted May 31, 2012 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 Quote
Administrators PlausiblyDamp Posted May 31, 2012 Administrators Posted May 31, 2012 I'll take your word on that as I'm still not entirely sure what your original problem was or how Extenstion methods directly compare to .ToString() either. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Doggo120 Posted June 1, 2012 Author Posted June 1, 2012 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 :) Quote
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.