The use of User-Defined Conversions

Hi guys,

I am studying C# and there are a lot of things to cover as you know.  I consider myself as an intermediate level C# developer and my goal is to be an advanced C# developer.

I know what this conversion is.
If somebody asks me what the interface is, I might be able to explain it and go deeper with a few code examples.
However, if somebody asks me the same questions for User-Defined Conversions, I might be able to highlight what it is in a high level, but won't be able to explain with code examples.

I have developed C# applications a few times at work, but I have never used User-Defined Conversions.

Do you guys use this type of conversions often at work?

I am just wondering if I have to study this part like other parts(class, method, async, interface etc.) of C#, or skip it for now and come back when I absolutely need it.(but in most cases, I don't think this will happen) I am familiar with other types of conversions(implicit, explicit, check, uncheck, boxing, unboxing, using 'is' and 'as', reference conversions etc.)

C# experts! Please give me any advice.
IzzyTwinklyAsked:
Who is Participating?
 
Jacques Bourgeois (James Burger)PresidentCommented:
I have been programming for 40 years, half 25 of them professionally, in different languages and environment, with applications that go from text processing to database to graphics to services to you name it. I have been programming in .NET since the first beta versions.

And I never had to use a custom conversion. I bet most programmers do not even ever heard the term before.

So, in my opinion, to answer your question, "come back when I absolutely need it".

Since it is rarely used, no need to be at ease with it. You know it exists, and that is sufficient for that kind of stuff. You will fall back on it if you ever need it. This is the case with a lot of features in modern languages. Operator overloading is one that comes to my mind.

Knowing they are there and that they exists is a kind of security net. They are like these tools that have been lying at the bottom of a drawer in the woodworking shops for years, and that you bought just in case. You almost forgot what they are used for, but you see them from time to time when looking for something else, so they hang somewhere in the back of your mind. Then, one day, you have a problem, and you remember that you have exactly the little gizmo that can solve it.
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
Yes, I used this a couple of times in my apps.

user-defined conversions is nothing else than a implicit conversion function defined in your class, which defines in on your class level what conversions are possible from within your class to some "external" class.

so if you know exactly what a explicit conversion function is, you know everything about that functionality
https://msdn.microsoft.com/en-us/library/aa288476%28v=vs.71%29.aspx
0
 
IzzyTwinklyAuthor Commented:
Hi James,

Thank you so much for your valuable advice. You have no idea how much your advice helped my situation.
Yes, I agree with your opinion on operator overloading too.
I guess that I've always known this but I really wanted to be confirmed by an expert like you.
From now on, I will skip/skim these kind of sections and focus on the essential skills.

Thanks again.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.