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 trialT Thomas
3,757 PointsWhy 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()
{
while(true){
Console.Write("Enter the number of times to print \"Yay!\": ");
var entry = Console.ReadLine();
try{
int yays = int.Parse(entry);
var count = 0;
while(count != yays){
Console.WriteLine("yay!");
count += 1;
}
break;
} catch(FormatException){
Console.WriteLine("You must enter a whole number.");
continue;
}
}
}
}
}
1 Answer
Eric Moody
12,373 PointsThe outer While loop is unnecessary. Get rid of it, the continue, and the break. You're good otherwise.
T Thomas
3,757 PointsThank you!
T Thomas
3,757 PointsT Thomas
3,757 PointsI'm pretty sure it has something to do w/
int yays = int.Parse(entry);