Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

C# C# Basics (Retired) Perfect Final

Why does this work in Workspaces, but not in C# Code Challenge?

I'm working on task 2 of the last Code Challenge in C# Basics.

It asks to add input validation. I assumed it was talking about the try/catch thing, which I added to the code.

This works in workspaces, but in the Code Challenge it says "Bummer. System.ArgumentNullException: Argument cannot be null. Parameter name: String. See output for stack trace.

Is it saying I have a null value? I'm not understanding whats happening.

using System;

namespace Treehouse.CodeChallenges
    class Program
        static void Main()
              Console.Write("Enter the number of times to print \"Yay!\": ");
              var entry = Console.ReadLine();

                int yays = int.Parse(entry);
                var count = 0;

                while(count != yays){
                  count += 1;
              } catch(FormatException){
                Console.WriteLine("You must enter a whole number."); 

I'm pretty sure it has something to do w/

int yays = int.Parse(entry);

1 Answer

The outer While loop is unnecessary. Get rid of it, the continue, and the break. You're good otherwise.

Thank you!