Skip to content
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

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open

Conversation

TooOldForThisGit
Copy link

I wrote this number app as a part of a exercise for school. This is my proposed solution for the stated problem.

@svenrog
Copy link
Owner

svenrog commented Aug 29, 2020

Ditt användarnamn motsvarar mina känslor när jag jobbar med React

var inputNumber = Console.ReadLine();

var inputStringArray = inputNumber.Split(',', StringSplitOptions.RemoveEmptyEntries);//new [] för FrameWork
var numbers = new double[inputStringArray.Length];
Copy link
Owner

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.

Copy link
Owner

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]);
Copy link
Owner

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
Copy link
Owner

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.

Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants