Q
Problem solve Get help with specific problems with your technologies, process and projects.

What do you think of me using 'new methods' instead of CStr?

I think there're still a difference between CStr and Convert.ToString (or sub function ToString), where we might get "nothing" if we use ToString function (instead of ""). But CStr will convert "nothing" to empty string. For example, if a query string is not found, then we get a "nothing" value for the string:

Dim myQs as string = Request.QueryString("qs").ToString

MyQs is nothing if query string has not been passed and causes a string manipulation error later. What is your idea if I still prefer to use "new methods" instead of CStr?

There's nothing like running into the nexus between the new VB.NET language and a piece for backwards compatibility. I would recommend using the new methods as they are much better supported across the breadth of the Common Language Runtime (CLR). What you need to do is add error handling on conversions such as the one you've shown.

The biggest problem I've been seeing in .NET application is that developers assume that everything just works and they never check for nothing/null values. Your main job as a developer is to add the error handling. Anyone can write a program that has perfect input and assumptions.

Dig Deeper on .NET tutorials, guides and quizzes

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.

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.

-ADS BY GOOGLE

SearchCloudComputing

SearchSoftwareQuality

TheServerSide.com

SearchCloudApplications

Close