In: Computer Science
Assume that the int.TryParse static method in .NET DOES NOT EXIST. Write your own TryParse method. Create a class named MyInt (so as not to conflict with existing Int32 class) and write the static TryParse method inside the MyInt class. Your MyInt.TryParse method is to duplicate the functionality of the existing .NET int.TryParse method EXACTLY. I want your MyInt.TryParse method to internally use the existing int.Parse method. Write a test console application that takes in a value from the user and validates it for integer input using your MyInt.TryParse method.
You may use any features of C# and/or any members of the .NET Framework (including int.Parse).
THIS IS TO BE DONE USING C#
C# CODE:(MyInt.cs)
using System;
class MyInt
{
static void Main()
{
//getting input from the user
Console.Write("Enter a integer
value: ");
string s= Console.ReadLine();
//calling the TryParse method to
validate the input
TryParse(s);
}
static void TryParse(string s)
{
try
{
// declaring a int variable
int r;
// getting parsed value
r = Int32.Parse(s);
Console.WriteLine("'{0}' parsed as {1}", s, r);
}
catch
(FormatException)
{
Console.WriteLine("Cannot Parse '{0}'", s);
}
}
}
SCREENSHOT FOR OUTPUT: