Run Code
|
API
|
Code Wall
|
Users
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
C# .ToInt() Extension Method Example
using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; using Extensions; // Calling extension method .ToInt() will convert a string to Int or throw the exception "Input string was not in a correct format." // This works for internal variables and also Console.ReadLine(); namespace Rextester { public class Program { public static void Main(string[] args) { Console.WriteLine("32".ToInt() + "55".ToInt()); //Console.WriteLine(Console.ReadLine().ToInt() + Console.ReadLine().ToInt()); } } } namespace Extensions { public static class StringExtensions { public static int ToInt(this string s) { int returnInt = 0; try { returnInt = Int32.Parse(s); } catch(Exception ex) { throw ex; } return returnInt; } } }
run
|
edit
|
history
|
help
2
Please
log in
to post a comment.
3
Homework1
Remove BOLD formatting from html
Math v9.1
Basic
Binary search tree - Post-order Traversal
fracOp
Fórum GroupBy ➡ Sum & Aggregate customers' names
Classes-and-Structures.cs
3
Please log in to post a comment.