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

How to convert string to int in C#?

WBOY
WBOYforward
2023-09-02 12:53:091291browse

How to convert string to int in C#?

Suppose our string is -

string str ="9999";

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

int n = Int32.Parse(str);

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);
   }
}

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!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete
Previous article:What are pointers in C#?Next article:What are pointers in C#?