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 5 11031
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
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
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
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
"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 This discussion thread is closed Replies have been disabled for this discussion. Similar topics
reply
views
Thread by Zlatko Matić |
last post: by
|
reply
views
Thread by Daimy |
last post: by
|
5 posts
views
Thread by Julien C. |
last post: by
|
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
| | | | | | | | | | |