console.writeline overload question

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



out of all the overloads that pop up via intellisense for
console.writeline() the following one confuses me:

Console.WriteLine (string format, params object[] arg)

1) whats the deal with 'params' there? I am used to this pattern: type var,
type var, type var etc... like: string str, int i, double x. This
console.writeline overload says 'params object[] arg' ?

2) I noticed that the console.writeline( string, object, object, object,
object) overload (from the help file - not intellisense) is not CLS
compliant. It says to use console.writeline(string, object[]). I am going to
write a class to assist me in some common console output tasks and would
like to make it as generic and flexible as possible so for example, I will
not know ahead of time the number of objects I may pass to a
console.writeline call. I have mostly seen the console.writeline used like
so:

console.writeline("some text: {0}, {1}, {2}", var1, var2, var3)

I see it with varying numbers of parameters... however if I am understanding
this correctly then if I wind up passing 4 parameters like so:

console.writeline("some text: {0}, {1}, {2}, {3}", var1, var2, var3, var4)
then it matches the console.writeline( string, object, object, object,
object) overload and will NOT be CLS compliant?

2b) and does this also mean that there is a limit of 4 parameters using this
pattern? for instance the following would not work?
console.writeline("some text: {0}, {1}, {2}, {3}, {4}", var1, var2, var3,
var4, var5)

3) if my assumptions above are correct and my intent is to be able to
utilize a console.writeline method inside a class which will need to work on
varying numbers of parameters is it true then that I should use
console.writeline( string, object[])?

hopefully my questions are clear enough... their probably not.

any input would be appreciated. Thanks.






.



Relevant Pages

  • Re: =?ISO-8859-1?Q?compare_two_structs_via_=3D=3D?=
    ... bool operator ==(string x, string y) ... I'm using the phrase "overload" as well. ... "Overriding" there is a mistake. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Method.property string
    ... GetData.Col.RowOverload Col to set or get the ... Then would I instantiate the Col class from within the GetData Class to call ... private string name; ... public string GetName() ...
    (microsoft.public.dotnet.framework)
  • Re: Operator Overloading (was: Hashtable)
    ... >>colour + for addition and concatenation to make errors stand out. ... > I a sense, there is another overload. ... > - conversion to string. ... concatenation can lead to surprising behaviour. ...
    (comp.lang.java.programmer)
  • Re: ostream, istream, and String^
    ... > Would you care to explain which error you see? ... both of which are something like 'no overload of '<<' ... This takes the output stream given as a parameter, ... So my problem is because String^ does not have a natural overload of '<<' ...
    (microsoft.public.dotnet.languages.vc)
  • Re: console.writeline overload question
    ... Console.WriteLine (string format, params object[] arg) ... That's a parameter array. ... object) overload and will NOT be CLS compliant? ...
    (microsoft.public.dotnet.languages.csharp)