Home > Backend Development > C#.Net Tutorial > How to convert string to int in C#?

How to convert string to int in C#?

WBOY
Release: 2023-09-02 12:53:09
forward
1290 people have browsed it

How to convert string to int in C#?

Suppose our string is -

string str ="9999";
Copy after login

Now, use Int32.Parse() to convert the string to integer -

int n = Int32.Parse(str);
Copy after login

Now display the integer value as shown in the following code -

Example

using System;
class Demo {
   static void Main() {
      string str ="9999";
      int n = Int32.Parse(str);
      Console.WriteLine(n);
   }
}
Copy after login

The above is the detailed content of How to convert string to int in C#?. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template