471,310 Members | 1,490 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,310 software developers and data experts.

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

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
1 1150
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.

Similar topics

4 posts views Thread by Bob | last post: by
2 posts views Thread by djc | last post: by
1 post views Thread by John Wright | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.