C # Optimizing string manipulation (experience)

Source: Internet
Author: User
Tags parse string

The 1.convert.toint32 and the int32.parse of the enmity

3 Ways to use 2.Split

3.@ the difference between "ABC" and "ABC" Is there

4. Keep 2-digit valid decimal and rounding

5.url Solution for delivering Chinese

6.3 Ways to convert 123456789 to 12-345-6789

7.4 ways to swap two characters at a specified location

8. The magical uses of "%10"

9. The ingenious way to output 21 aaaaaaaaaaaaaaaaaaaaa

The 1.convert.toint32 and the int32.parse of the enmity

All 2 of these methods can parse string to int, then we must have a question: what is the difference between them? When should I use what? Performance and so on.

In fact, in 2.0 and Int32.TryParse also achieved the same effect.

C # CODE

using System;using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication1
...
{
class Program
...
{
static void Main(string[] args)
...
{
string myString = "1234";
int myint = 0;
myint = Convert.ToInt32(myString);
Console.Write(myint+"\r\n ");
myint = Int32.Parse(myString);
Console.Write(myint+"\r\n ");
Int32.TryParse(myString, out myint);
Console.Write(myint+"\r\n");
}
}}

(The running effect will be no different, Tullo)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.