I have a method definition like this:
public void Log(Exception ex, ExceptionLevel exceptionLevel, params string[] optionalInfo)
{
//Log the exception and such here.
}
And then if I make a method call to this method, like such:
Log(new Exception("This is a test message"), ExceptionLevel.Low, "Testing", "Exception Handling", "Operation");
The method will not get passed the very first argument, "Testing", that is passed to it and I end up with an array comprised of "Exception Handling" and "Operation", no first argument.
Has anyone else run into this issue?
Loading

AlanRank #669 · 3.6K reputationPosted Mar 2, 2008, 1:32 PM EST
Hi Brandon,
As far as I'm aware, there are no known bugs with the params keyword.
What happens if you pass just the first optional argument. Does optionalInfo[0] == "Testing" or is the length of the array zero?
Posted Mar 2, 2008, 1:56 PM EST
Im a fairly experienced developer but rarely use the params keyword, but when I do its usually for something rather important :)
As for your suggestion, I tried that and it comes up with an array length of zero. It has me stumped. I can always find work arounds but this way is optimal for what I want to do. I dont want to have to create and pass an array each time I want to log an exception (yikes!), thats simply just not practical :)
Posted Mar 2, 2008, 2:03 PM EST
Wait a second! I just figured it out! I have another method with similar parameters except that method has a "string message" argument before the params string[] argument. Hm... now to figure out how to get a work around. Man do I feel like a dummy, haha!
RESOLVED:
I figured it out, I just put the "string message" argument as the first argument in that particular method and its fine now, well that was an interesting issue. Thanks for the help Alan