fbpx

Casting - the general case etc.

More
1 year 1 month ago #1 by Phil Hepburn
Casting - the general case etc. was created by Phil Hepburn
Hi Robert, Chris and Team,

I have a small problem / issue and need some help please.

I wish to be able to write code so that a cast I make can be done in a general way and not by me typing a specific class name / type. The attached very small image will help explain what I am after.



In line 114 I wish to provide a variable name and not 'Double' - as in the end I am to make some very general code where the Type comes in as a parameter, or Generic type.

I seem to have tried most things with Type and typeof() and GetType() etc., but have not coded as yet in a Generic fashion.

What is the correct and proper way to do this ?

HELP !!! please,
Phil.
Attachments:

Please Log in or Create an account to join the conversation.

More
1 year 1 month ago #2 by Robert van der Hulst
Replied by Robert van der Hulst on topic Casting - the general case etc.
Phil,
What are you trying to do ?
If you want to create a method that takes "any type" you should use a generic type parameter:


Robert

XSharp Development Team
The Netherlands
This email address is being protected from spambots. You need JavaScript enabled to view it.

Please Log in or Create an account to join the conversation.

More
1 year 1 month ago #3 by Phil Hepburn
Replied by Phil Hepburn on topic Casting - the general case etc.
Hi Robert,

Yes, thanks - I now have my "foot in the door" to solving my problem.

This is what I have done to research my possible solution.







I think this approach should solve my problems !?

Although what I am doing is an interesting X# coding challenge, it may not be of much day-to-day use to many / any folks.

However, I have built a basic class wrapper around the System.Array class so that I now have a functioning single array class which allows any value index limits. The test class worked for STRING and I was trying to convert it to accept any array item class.

Nearly there I feel.

Project task is a good one to help improve our X# syntax 'mastery' - so don't say its a waste of time. And, it makes some useful code to include in the ClickStartXSharp eNotes.

More on this stuff when I get it to work 100%

Thanks for trying to help.
Cheers,
Phil.
Attachments:

Please Log in or Create an account to join the conversation.