473,795 Members | 2,980 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(f ormat, parameters);

m_outputBox.Ite ms.Add(buff);

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

m_debug.PrintDe bugError("Loade d {0} shots from the database...", someValue);

I get the obvious error:
The best overloaded method match for 'CAppDebug.Prin tDebugError(str ing,
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 11156
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(f ormat, parameters);

m_outputBox.Ite ms.Add(buff);

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

m_debug.PrintDe bugError("Loade d {0} shots from the database...", someValue);

I get the obvious error:
The best overloaded method match for 'CAppDebug.Prin tDebugError(str ing,
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*********@di scussions.micro soft.com> wrote in message
news:5E******** *************** ***********@mic rosoft.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(f ormat, parameters);

m_outputBox.Ite ms.Add(buff);

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

m_debug.PrintDe bugError("Loade d {0} shots from the database...", someValue);
I get the obvious error:
The best overloaded method match for 'CAppDebug.Prin tDebugError(str ing,
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(f ormat, parameters);

m_outputBox.Ite ms.Add(buff);

}

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

I get the obvious error:
The best overloaded method match for
'CAppDebug.Prin tDebugError(str ing,
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*********@di scussions.micro soft.com> wrote in message
news:5E******** *************** ***********@mic rosoft.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(f ormat, parameters);

m_outputBox.Ite ms.Add(buff);

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

m_debug.PrintDe bugError("Loade d {0} shots from the database...", someValue);
I get the obvious error:
The best overloaded method match for 'CAppDebug.Prin tDebugError(str ing,
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***@asdfasdf sd.com> wrote in message
news:OD******** ********@TK2MSF TNGP10.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(f ormat, parameters);

m_outputBox.Ite ms.Add(buff);

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

m_debug.PrintDe bugError("Loade d {0} shots from the database...",
someValue);

I get the obvious error:
The best overloaded method match for 'CAppDebug.Prin tDebugError(str ing,
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
3324
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 appear when someone is trying to use it as front-end for real server database systems such as PostgreSQL or MySQL. One of these problems is regarding pass-through queries and parameters. I wanted to have all the code on client, while executing it on...
0
1862
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 with the security settings requirement inorder to do the
5
7829
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 to the Item page "ViewItem.aspx" with a simple : Server.Transfer("ViewItem.aspx"); I'd like to pass another HTTP parameter so that in the "ViewItem.aspx" page,
2
17111
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 Pass="AAA", I get Params("Username") = "alex, Pass=AAA" and Params("Pass")="", which is not what I expected.
4
5295
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 is passed that the field in the db is left empty and NULL is not entered in. So how can I pass a NULL value in a hashtable, execute the stored procedure and have NULL entered in the table instead of a blank field? here is an example of the code:...
4
2328
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 looked like the simple and good solution but no. class Example { string format = "{1} {2} {3}" string anotherFormat = "{3}{1}{2}";
5
1456
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 I write the function to accept these as parameters in a method, or should I make them properties? Can I make certain properties required?
9
1639
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 ) then args _will_ be null because the compiler can implicitly convert the
6
4738
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 format: struct mst_ {
0
9673
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9522
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10448
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9046
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6784
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5566
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4114
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3730
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2922
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.