Q

System.Convert.ToString(mdblAnswer) or CStr(mdblAnswer)? Which should I use?

In trying to learn VB.NET from various books, I find that one author uses System.Convert.ToString(mdblAnswer) and another uses the much shorter named function CStr(mdblAnswer). Is there any advantage to using one of these approaches over the other? If so, which approach do you feel is best and why? Thanks so much for sharing your expertise. One thing that is very amusing between us all "experts" is that a lot of knowledge comes from...

past experiences and "how we feel." I can tell you that when you start dealing with multiple languages, each one changes your perception, and whilst you move from one to another, this begins to make things more fuzzy.

The CSTR function is a derivative from the old BASIC days, back in the 1980s. BASIC stands for:

B-EGINNERS
A-LL-PURPOSE
S-YMBOLIC
I-NSTRUCTION
C-ODE

Now, the CSTR function came about because in those days, each instruction was compiled and held in its interpreted form in a minimal amount of memory. The fewer letters you used for a function, the less memory it consumed and the larger you applications could be. Nowadays, with a couple of gigabytes of memory and 40 GB of HD space, this has become less of an issue.

The .NET Framework attempts to standardize the way in which functions work. And to be honest, whilst you use CSTR in VB.NET, if you decide to make the move to C#, you'll find that a lot of blankets used to pad people in the VB world, have suddenly been removed.

You might even notice that with each object there is usually a sub property 'ToString' -- this is exactly the same.

So the quick answer, is no -- it makes no difference; it's all personal choice.

This was first published in March 2003

Dig deeper on Win Development Resources

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

0 comments

Oldest 

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

-ADS BY GOOGLE

SearchCloudComputing

SearchSoftwareQuality

SearchSOA

TheServerSide

SearchCloudApplications

Close