473,395 Members | 1,457 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 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 1219
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.