By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,567 Members | 1,651 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,567 IT Pros & Developers. It's quick & easy.

Add functionality to Console.WriteLine, sort of like defining a ma

P: n/a
I am trying to create a class or function which does one extra thing then
performs a normal Console.WriteLine, preferrably with all the overloads
available and intact.

Where I currently have:

Console.Write("\r
\r");
// note, the previous line is simply clearing any text on the current
console line without leaving that lnie.
Console.WriteLine("{0} {1} {2} {3} ({4})", new object[] {var1, var2, var3,
var4, var5});

I'd like to do

MyClass.OverwriteLine("{0} {1} {2} {3} ({4})", new object[] {var1, var2,
var3, var4, var5});

and get the same result, with all WriteLine overloads available for
OverwriteLine, and hopefully without having to duplicate them all.

Can anyone help me out with this?

I asked some friends and one idea was the following, and it is better than
the extra Console.Write each time, but I am still hoping for more:

static string SomeMethod(string toPad)
{
return "\r
\r" + toPad;
}

Console.WriteLine(SomeMethod("here is a string {0} : {1}"), new
object[]{"some", 5});

I'm using Framework 2.0.

Erik
Jul 8 '08 #1
Share this Question
Share on Google+
1 Reply


P: n/a
There isnt any way to add a static method to the Console class but you can
easily make your own with passed through the calls to the Console class but
adds your prefix on to the string.
The suggestion of having a function to do that probably isnt terrible either
as you are really stuck for options with what you want to do as far as I know.
--
Ciaran O''Donnell
http://wannabedeveloper.spaces.live.com
"Erik Eckhardt" wrote:
I am trying to create a class or function which does one extra thing then
performs a normal Console.WriteLine, preferrably with all the overloads
available and intact.

Where I currently have:

Console.Write("\r
\r");
// note, the previous line is simply clearing any text on the current
console line without leaving that lnie.
Console.WriteLine("{0} {1} {2} {3} ({4})", new object[] {var1, var2, var3,
var4, var5});

I'd like to do

MyClass.OverwriteLine("{0} {1} {2} {3} ({4})", new object[] {var1, var2,
var3, var4, var5});

and get the same result, with all WriteLine overloads available for
OverwriteLine, and hopefully without having to duplicate them all.

Can anyone help me out with this?

I asked some friends and one idea was the following, and it is better than
the extra Console.Write each time, but I am still hoping for more:

static string SomeMethod(string toPad)
{
return "\r
\r" + toPad;
}

Console.WriteLine(SomeMethod("here is a string {0} : {1}"), new
object[]{"some", 5});

I'm using Framework 2.0.

Erik
Jul 9 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.