I was curious -- and they say curiosity killed the cat. What I was curious about was whether it was possible to somehow just write "WriteLine()" instead of "Console.WriteLine()".
It is, but how worthwhile or good of an idea it is is open to question.
Here is the code from the last "delay" example where we ended up talking about properties.
using System; using static System.Console; using System.Threading.Tasks; namespace Example { public class Wally { public static int Delay { private get; set; } public static void chat ( string msg, int repeat ) { for ( int i=0; i<repeat; i++ ) { WriteLine ( msg ); Thread.Sleep ( Delay ); } } } } namespace HogHeaven { public class Program { public static void Main(string[] args) { Example.Wally.Delay = 1000; Example.Wally.chat ( "Kilroy is here !!", 4 ); WriteLine ( "All done" ); } } } // THE ENDI've ripped out all the commented lines from the last example so this is nice and tidy.
using static System.Console;You can't just say "using System.Console" because "using" must refer to namespaces and "Console" is a class inside of the System namespace. But we can use the static word here. We use it for everything! All I can say is that it works, at this point the explanation is beyond me, and so far I am too lazy to dig that deep into this. It lets us refer to the WriteLine() method without giving the class or namespace. As I say, I'm not sure this is wise, recommendable, or worthwhile, but now we all know.
Tom's Computer Info / [email protected]