?
Solved

Convert Datatypes...

Posted on 2005-03-23
5
Medium Priority
?
177 Views
Last Modified: 2010-04-16
Hello, in vb.net i use to use cStr or cLng etc.. to convert string from one cast to another... what do you do on c#?
0
Comment
Question by:wd006451
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 3

Accepted Solution

by:
hackman_3vilGuy earned 180 total points
ID: 13615492
Use casting whereby you put the type you want to convert to in brackets followed by what you want to convert

string a = "5";
int b = (int) a;

Or use:

System.Convert..... This contains methods for converting between nearly all datatypes.

Or use the Parse method if available eg:

string a  = "23/03/2005";
DateTime b = DateTime.Parse(a);

Enjoy
0
 
LVL 5

Expert Comment

by:Tertioptus
ID: 13615878
you should use Parse when going from a string to numeric value.

and Convert for all other cases
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question