472,992 Members | 3,765 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,992 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 1206
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: jabailo | last post by:
This is driving me crazy. I finally got the Remoting sample chat application working almost. When I run the chat client in VS.NET it goes into an endless loop -- that's because I assume that...
1
by: Oz | last post by:
This is long. Bear with me, as I will really go through all the convoluted stuff that shows there is a problem with streams (at least when used to redirect stdout). The basic idea is that my...
2
by: Gulshan Oshan | last post by:
I want to implement a simple console that continuously listens for an event from a custom object. I am unable to capture the events from the object. If I subscribe to the events in a windows app...
7
by: shawnk | last post by:
Hello Everyone How do you format format numbers right-justified using Console.WriteLine(), i.e I need to line up numbers in vertical columns and the MSDN documentation is pretty poor Here is the...
3
by: Wayne | last post by:
I have a console application (ssh2.exe) that requires keystrokes to be sent to it after activating. I have worked that it needs to be started in it own thread, but capturing the process and...
4
by: Bob | last post by:
I just recently noticed that when I start my applicatoin in debug mode, the IDE hangs (no disk or CPU activity) indefinitely (at least 20 minutes). Pausing the application shows that it's hung up...
2
by: djc | last post by:
out of all the overloads that pop up via intellisense for console.writeline() the following one confuses me: Console.WriteLine (string format, params object arg) 1) whats the deal with...
1
by: John Wright | last post by:
I am running a console application that connects to an Access database (8 million rows) and converts it to a text file and then cleans and compacts the database. When it runs I get the following...
2
by: nautonnier | last post by:
Hello, I have a C# app that spawns several processes each containing a console app written by another developer in C++. The console app was written first to be just like a console app: it...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
3
SueHopson
by: SueHopson | last post by:
Hi All, I'm trying to create a single code (run off a button that calls the Private Sub) for our parts list report that will allow the user to filter by either/both PartVendor and PartType. On...

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.