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 trialandrewgabriel
18,106 PointsWhy can't we add Console under using at the top?
I was wondering why we can't have "using Console;" at the top of our file to reduce typing console every time since I believe that's considered also part of the library. I have tried it before asking and saw a bunch of errors but I am just curious as to the reason behind it.
Thanks!
1 Answer
Steven Parker
231,236 PointsThe using statement is for namespaces.
But Console is a class, not a namespace.
You could, of course, define your own property or method:
using System;
public myclass()
{
static string ReadLine() => Console.ReadLine(); // private abbreviations
static void WriteLine(string s) => Console.WriteLine(s);
public mymethod()
{
WriteLine("Enter your name:");
string name = ReadLine();
WriteLine($"Hello, {name}");
}
}
andrewgabriel
18,106 Pointsandrewgabriel
18,106 PointsMakes sense. Thanks for the explanation :)