Question

In: Computer Science

Assume that the int.TryParse static method in .NET DOES NOT EXIST. Write your own TryParse method....

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#

Solutions

Expert Solution

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:


Related Solutions

Write your own version of a class template that will create a static stack of any...
Write your own version of a class template that will create a static stack of any data type. Demonstrate the class with a driver program. please make a version to copy.
Write a static method called "evaluate" that takes a string as a parameter
In Java language  Write a static method called "evaluate" that takes a string as a parameter. The string will contain a postfix expression, consisting only of integer operands and the arithmetic operators +, -, *, and / (representing addition, subtraction, multiplication, and division respectively). All operations should be performed as integer operations. You may assume that the input string contains a properly-formed postfix expression. The method should return the integer that the expression evaluates to. The method MUST use a stack...
Name the project pa3 [Method 1] In the Main class, write a static void method to...
Name the project pa3 [Method 1] In the Main class, write a static void method to print the following text by making use of a loop. Solutions without a loop will receive no credit. 1: All work and no play makes Jack a dull boy. 2: All work and no play makes Jack a dull boy. 3: All work and no play makes Jack a dull boy. 4: All work and no play makes Jack a dull boy. [Method 2]...
3. [Method 1] In the Main class, write a static void method to print the following...
3. [Method 1] In the Main class, write a static void method to print the following text by making use of a loop. Solutions without a loop will receive no credit. 1: All work and no play makes Jack a dull boy. 2: All work and no play makes Jack a dull boy. 3: All work and no play makes Jack a dull boy. 4: All work and no play makes Jack a dull boy. 4. [Method 2] In the...
Name the project pa3 [Method 1] In the Main class, write a static void method to...
Name the project pa3 [Method 1] In the Main class, write a static void method to print the following text by making use of a loop. Solutions without a loop will receive no credit. 1: All work and no play makes Jack a dull boy. 2: All work and no play makes Jack a dull boy. 3: All work and no play makes Jack a dull boy. 4: All work and no play makes Jack a dull boy. [Method 2]...
Using your own words, explain how the direct write-off method and the allowance method applied in...
Using your own words, explain how the direct write-off method and the allowance method applied in accounting for uncollectible accounts receivables? Give me an explanation of the difference between revenue expenditures, and capital expenditures, and how they are recorded in the accounting system using your own words. Type or paste question here
Write in your own words without copy and paste from the net about " describe the...
Write in your own words without copy and paste from the net about " describe the differences between mitosis and meiosis " total words ( 600 - 700 ) in detail the short essay must contain 1- Introduction 2- Body 3- Conclusion Note: please do not copy and paste from the net
Write in your own words without copy and paste from the net about " describe the...
Write in your own words without copy and paste from the net about " describe the differences between mitosis and meiosis" total words ( 700-800 ) In detail please the short essay must contain 1- Introduction 2- Body 3- Conclusion Note: please do not copy and paste from the net
// ==== Challenge 1: Write your own closure ==== // Write a closure of your own...
// ==== Challenge 1: Write your own closure ==== // Write a closure of your own creation. // Keep it simple! Remember a closure is just a function // that manipulates variables defined in the outer scope. // The outer scope can be a parent function, or the top level of the script. /* STRETCH PROBLEMS, Do not attempt until you have completed all previous tasks for today's project files */ // ==== Challenge 2: Implement a "counter maker" function...
FOR JAVA: Need to write a code for the implementation of this public static method: findLongestPalindrome...
FOR JAVA: Need to write a code for the implementation of this public static method: findLongestPalindrome takes a Scanner scn as its parameter and returns a String. It returns the longest token from scn that is a palindrome (if one exists) or the empty string (otherwise). (Implementation note: You'll find your isPalindrome method helpful here. This method calls for an optimization loop.)
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT