

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
C# int.Parse Vs int.TryParse Method
Convert a string representation of number to an integer,using the int.TryParse and intParse method in C#.
If the string cannot be converted, then the int.TryParse method returns false i.e. a Boolean value, whereas int.Parse returns an exception.
Let us see an example of int.Parse method −
Example
using System.IO; using System; class Program { static void Main() { int res; string myStr = "120"; res = int.Parse(myStr); Console.WriteLine("String is a numeric representation: "+res); } }
Output
String is a numeric representation: 120
Let us see an example of int.TryParse method.
Example
using System.IO; using System; class Program { static void Main() { bool res; int a; string myStr = "120"; res = int.TryParse(myStr, out a); Console.WriteLine("String is a numeric representation: "+res); } }
Output
String is a numeric representation: True
- Related Questions & Answers
- int(5) vs. int(10) in MySQL?
- What does the method fill(int[], int fromIndex, int toIndex, int val) do in java?
- MySQL BigInt zerofill vs int zerofill?
- What does the method sort(int[] a, int fromIndex, int toIndex) do in java?
- What does the method copyOfRange(int[] original, int from, int to) do in java?
- What does the method fill(obj[], int fromIndex, int toIndex, int val) do in java?
- What does the method fill(int[], int val) do in java?
- Matcher region(int start, int end) method in Java with Examples
- IntArray vs. Array<Int> in Kotlin
- What does the method removeRange(int fromIndex, int toIndex) do in java?
- What does the method equals(int[] a1, int[] a2) do in java?
- What does the method copyOf(int[] original, int newLength) do in java?
- How to parse a string to an int in C++?
- Difference between const int*, const int * const, and int const * in C
- Difference between const int*, const int * const, and int const * in C/C++?
- What is the difference between const int*, const int * const, and int const *?
Advertisements