Sign in to follow this  
MrMaker

Is there a better way to do this?

Recommended Posts

MrMaker    128

Is there a better way of doing this more efficiently and better way? It runs and calculates the area but I think there is a better way.

 

Code Below:

 

[source lang="csharp"]

namespace LearningCsharp
{
    class Program
    {
        static void Main(string[] args)
        {
           
            Console.WriteLine("Enter length");
 
            string length = Console.ReadLine();
 
            int.Parse(length);
 
            int newLength = Convert.ToInt32(length);
 
            Console.WriteLine("Enter width");
 
            string width = Console.ReadLine();
 
            int.Parse(width);
 
            int newWidth = Convert.ToInt32(width);
 
            Console.WriteLine(newLength * newWidth + "cm");
 
            Console.ReadLine();
        }
    }
}
[/source]

Share this post


Link to post
Share on other sites
Nypyren    12063
Convert.ToInt32(string) and int.Parse(string) are identical. Convert.ToInt32's main use is that you can pass it things besides strings and convert those to an int as well.

Choose one or the other but not both.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this