468,780 Members | 2,181 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,780 developers. It's quick & easy.

pass n params like String.Format()

I have a simple debug and logging class and I would like to be able to send
a non-formatted string to my various printing methods, much like
string.format().

I have tried to implement this like so:
public void PrintDebugError(string format, object[] parameters)

{

string buff = string.Format(format, parameters);

m_outputBox.Items.Add(buff);

}
Then when calling it like this:
int someValue = 666;

m_debug.PrintDebugError("Loaded {0} shots from the database...", someValue);

I get the obvious error:
The best overloaded method match for 'CAppDebug.PrintDebugError(string,
object[])' has some invalid arguments
So looking at the string.format(), how do they do it? If I create an object
array, then store the int into the array and pass that, it works fine.
I guess what I'm looking for is a way to specify n parameters..

Any ideas?
-SK
Nov 16 '05 #1
5 10954
Hi sklett,

Use the params keyword.
http://msdn.microsoft.com/library/en...clrfparams.asp

For example:
public void Format(params string[] args)

HTH,
Rakesh Rajan

"sklett" wrote:
I have a simple debug and logging class and I would like to be able to send
a non-formatted string to my various printing methods, much like
string.format().

I have tried to implement this like so:
public void PrintDebugError(string format, object[] parameters)

{

string buff = string.Format(format, parameters);

m_outputBox.Items.Add(buff);

}
Then when calling it like this:
int someValue = 666;

m_debug.PrintDebugError("Loaded {0} shots from the database...", someValue);

I get the obvious error:
The best overloaded method match for 'CAppDebug.PrintDebugError(string,
object[])' has some invalid arguments
So looking at the string.format(), how do they do it? If I create an object
array, then store the int into the array and pass that, it works fine.
I guess what I'm looking for is a way to specify n parameters..

Any ideas?
-SK

Nov 16 '05 #2
perfect, thanks!!
"Rakesh Rajan" <Ra*********@discussions.microsoft.com> wrote in message
news:5E**********************************@microsof t.com...
Hi sklett,

Use the params keyword.
http://msdn.microsoft.com/library/en...clrfparams.asp

For example:
public void Format(params string[] args)

HTH,
Rakesh Rajan

"sklett" wrote:
I have a simple debug and logging class and I would like to be able to send a non-formatted string to my various printing methods, much like
string.format().

I have tried to implement this like so:
public void PrintDebugError(string format, object[] parameters)

{

string buff = string.Format(format, parameters);

m_outputBox.Items.Add(buff);

}
Then when calling it like this:
int someValue = 666;

m_debug.PrintDebugError("Loaded {0} shots from the database...", someValue);
I get the obvious error:
The best overloaded method match for 'CAppDebug.PrintDebugError(string,
object[])' has some invalid arguments
So looking at the string.format(), how do they do it? If I create an object array, then store the int into the array and pass that, it works fine.
I guess what I'm looking for is a way to specify n parameters..

Any ideas?
-SK

Nov 16 '05 #3
Wes
Hello sklett,

take a look at the params keyword.

public void PrintDebugError(string format, params object[] parameters)...

HTH
Wes Haggard
http://weblogs.asp.net/whaggard/

I have a simple debug and logging class and I would like to be able to
send a non-formatted string to my various printing methods, much like
string.format().

I have tried to implement this like so:
public void PrintDebugError(string format, object[] parameters)
{

string buff = string.Format(format, parameters);

m_outputBox.Items.Add(buff);

}

Then when calling it like this:
int someValue = 666;
m_debug.PrintDebugError("Loaded {0} shots from the database...",
someValue);

I get the obvious error:
The best overloaded method match for
'CAppDebug.PrintDebugError(string,
object[])' has some invalid arguments
So looking at the string.format(), how do they do it? If I create an
object
array, then store the int into the array and pass that, it works fine.
I guess what I'm looking for is a way to specify n parameters..
Any ideas?
-SK


Nov 16 '05 #4
Anytime sklett :)

- Rakesh Rajan
"sklett" wrote:
perfect, thanks!!
"Rakesh Rajan" <Ra*********@discussions.microsoft.com> wrote in message
news:5E**********************************@microsof t.com...
Hi sklett,

Use the params keyword.
http://msdn.microsoft.com/library/en...clrfparams.asp

For example:
public void Format(params string[] args)

HTH,
Rakesh Rajan

"sklett" wrote:
I have a simple debug and logging class and I would like to be able to send a non-formatted string to my various printing methods, much like
string.format().

I have tried to implement this like so:
public void PrintDebugError(string format, object[] parameters)

{

string buff = string.Format(format, parameters);

m_outputBox.Items.Add(buff);

}
Then when calling it like this:
int someValue = 666;

m_debug.PrintDebugError("Loaded {0} shots from the database...", someValue);
I get the obvious error:
The best overloaded method match for 'CAppDebug.PrintDebugError(string,
object[])' has some invalid arguments
So looking at the string.format(), how do they do it? If I create an object array, then store the int into the array and pass that, it works fine.
I guess what I'm looking for is a way to specify n parameters..

Any ideas?
-SK


Nov 16 '05 #5
"sklett" <as***@asdfasdfsd.com> wrote in message
news:OD****************@TK2MSFTNGP10.phx.gbl...
I have a simple debug and logging class and I would like to be able to send
a non-formatted string to my various printing methods, much like
string.format().

I have tried to implement this like so:
public void PrintDebugError(string format, object[] parameters)

{

string buff = string.Format(format, parameters);

m_outputBox.Items.Add(buff);

}
Then when calling it like this:
int someValue = 666;

m_debug.PrintDebugError("Loaded {0} shots from the database...",
someValue);

I get the obvious error:
The best overloaded method match for 'CAppDebug.PrintDebugError(string,
object[])' has some invalid arguments
So looking at the string.format(), how do they do it? If I create an
object
array, then store the int into the array and pass that, it works fine.
I guess what I'm looking for is a way to specify n parameters..

Any ideas?


Look up the "params" keywword. If you define your method as
public void PrintDebugError(string format, params object[] parameters)
then it should work.

Chris Jobson
Nov 16 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Alex Nitulescu | last post: by
4 posts views Thread by CsharpGuy | last post: by
4 posts views Thread by carry | last post: by
5 posts views Thread by Larry Bud | last post: by
9 posts views Thread by =?Utf-8?B?UElFQkFMRA==?= | last post: by
6 posts views Thread by (2b|!2b)==? | last post: by
1 post views Thread by CARIGAR | last post: by
2 posts views Thread by Marin | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.