Jump to content

View more

Image of the Day

Boxes as reward for our ranking mode. ヾ(☆▽☆)
#indiedev #gamedev #gameart #screenshotsaturday https://t.co/ALF1InmM7K
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.


Sign up now

Is there a better way to do this?

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


  • You cannot reply to this topic
3 replies to this topic

#1 MrMaker   Members   

128
Like
0Likes
Like

Posted 19 July 2013 - 07:30 PM

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:

 

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();
        }
    }
}


#2 Pink Horror   Members   

2459
Like
0Likes
Like

Posted 19 July 2013 - 07:33 PM

Delete the int.Parse lines.



#3 Nypyren   Members   

11832
Like
0Likes
Like

Posted 19 July 2013 - 10:31 PM

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.

#4 NightCreature83   Members   

4949
Like
0Likes
Like

Posted 21 July 2013 - 02:03 AM

Also Parse is not exception safe so you would have to use a try catch clause around it. There is a TryParse function as well that is exception safe.


Worked on titles: CMR:DiRT2, DiRT 3, DiRT: Showdown, GRID 2, theHunter, theHunter: Primal, Mad Max





Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.