472,782 Members | 1,163 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,782 software developers and data experts.

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 11105
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Zlatko Matić | last post by:
Hi everybody! Recently I was struggling with client/server issues in MS Access/PostgreSQL combination. Although Access is intuitive and easy to use desktop database solution, many problems...
0
by: Daimy | last post by:
I meet the same problem below, please help me! Thanks! //written by some one I have developed a windows forms user control, which I am going to host in Internet Explorer.. I am familiar...
5
by: Julien C. | last post by:
Hi all, I have an "EditeItem.aspx" page which lets me edit properties of an "Item". In the OnClick() event of my Save button, I do save Item changes to the database and then I redirect the user...
2
by: Alex Nitulescu | last post by:
Hi. I have tried to pass two parameters, like this: Response.Redirect(String.Format("NewPage.aspx?Username={0}, Pass={1}", txtUserName.Text, txtPass.Text)) But if I pass Username="Alex" and...
4
by: CsharpGuy | last post by:
I took over an web app (C#) were the developer put everything in a has table then called a method to execute a stored procedure, now I'm running into some issues were if I do an update and a NULL...
4
by: carry | last post by:
Hi everybody, I need simple string formatting like string.Format() does, but just with strings what seems not to work. Can anyone tell me please why this doesn't work and how can it be done? This...
5
by: Larry Bud | last post by:
I'm writing a class to create a specifically formatted fixed width file. It's 800 characters wide, consisting of approx 30 fields. So I need to pass 30 variables, maybe 10 are required. Should...
9
by: =?Utf-8?B?UElFQkFMRA==?= | last post by:
Given a method like void F ( params object args ) { ... } I had always _assumed_ that args would never be null, but now it's been brought to my attention that if the caller uses F ( null )...
6
by: (2b|!2b)==? | last post by:
I am expecting a string of this format: "id1:param1,param2;id2:param1,param2,param3;id" The tokens are seperated by semicolon ";" However each token is really a struct of the following...
0
by: Rina0 | last post by:
Cybersecurity engineering is a specialized field that focuses on the design, development, and implementation of systems, processes, and technologies that protect against cyber threats and...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 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
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
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=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth

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.