-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Numbers app #14
base: master
Are you sure you want to change the base?
Numbers app #14
Conversation
Ditt användarnamn motsvarar mina känslor när jag jobbar med |
var inputNumber = Console.ReadLine(); | ||
|
||
var inputStringArray = inputNumber.Split(',', StringSplitOptions.RemoveEmptyEntries);//new [] för FrameWork | ||
var numbers = new double[inputStringArray.Length]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prova att använda en nullbar datatyp här för att hålla reda på om Double.TryParse
lyckats eller inte. Om man inte gör det påverkas snittet.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
//while() | ||
for (int i = 0; i < inputStringArray.Length; i++) | ||
{ | ||
Console.WriteLine("Värdet är:".PadRight(14) + inputStringArray[i]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Att använda metodaccess direkt följande literaler på detta sättet är något vi anser påverkar läsbarheten i kod.
Vidare så körs operationen PadRight
multipla gånger iom att den är placerad i loopen utan att värdet förändras under körning.
Skriv istället:
var label = "Värdet är:";
var paddedLabel = label.PadRight(14);
for (int i = 0; i < inputStringArray.Length; i++)
{
Console.WriteLine(paddedLabel + inputStringArray[i]);
|
||
//Printing out evaluated values | ||
Console.WriteLine(line); Console.WriteLine(); | ||
Console.WriteLine($"Högsta värdet: {numbersArray.Max()}");//Max value |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Här kallas numbersArray.Max() igen, även fast det redan görs på rad 63.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Vidare så tar numbersArray.Min() och numbersArray.Min() inte hänsyn till om det uppstått fel i parseing ovan.
Dvs att om värdena anders,12,34,5
anges kommer Min()
att returnera 0.
I wrote this number app as a part of a exercise for school. This is my proposed solution for the stated problem.