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 Strings Combining Strings

Zachary Lach
Zachary Lach
1,106 Points

C# Basics eat method

Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object. Any idea why?

Program.cs
using System;

class Program
{
    static string Eat(string first, string second)
    {
        Console.Write("I think {0} and {1} are tasty!", first, second);
        return Console.ReadLine();
    }

    static void Main()
    {
        Console.WriteLine(Eat("apples", "blueberries"));
        Console.WriteLine(Eat("carrots", "daikon"));
    }
}

1 Answer

Steven Parker
Steven Parker
231,271 Points

You're not supposed to do any console operations in this method (write or read).. Instead, the method should return the formatted string.