• Advertisement
Sign in to follow this  

Is there a better way to do this?

This topic is 1647 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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
Advertisement
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
Sign in to follow this  

  • Advertisement