473,854 Members | 1,526 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 11158
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
3329
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
1865
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
7836
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
17119
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
5299
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
1458
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
1640
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
4739
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
11024
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
10678
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10751
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7914
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5740
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5940
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4557
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
4153
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3185
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.