optional-parameters

how to run my own jQuery function correctly?

I've got this code that's changing a picture and additional link with it. var imgSwap(pic, link){ $("#sampleimg") .load(function () { $(this).hide(); $('#indexPic').removeClass('loading'); $(this).fadeIn(500); }) .error(function () {}) .attr({src : picArray[5]});...

How do you handle multi-argument JavaScript functions?

I have defined my JavaScript function as follows: function printCompanyName(company1, company2, company3, company4, company5) { document.write("<p>" + company1 + "</p>"); document.write("<p>" + company2 + "</p>"); document.write("<p>" + company3 + "</p>"); document.write("<p>" + company4 + "</p>"); document.write("<p>" + company5 + "</p...

Can you still do variable arguments in C the old way?

Purely for interest, I am re-learning C after ... I don't know ... 15 - 20 years. I seem to recall that variable arguments were implemented as simple macros. Can anyone remember what they were? Edit: To clarify my question, I know they had the same name as va_list etc. but can you remember the actual macro definition? Will they st...

iis7 url rewrite - optional querystring parameters

Hi, I'm using the iis7 URL Rewrite module and it's working fine, except for two things. Being new to this, I might be missing something obvious. 1) My URL gets converted from www.mysite.com/search.aspx?fName=John&sName=Smith to www.mysite.com/John/Smith. This works fine, but if I add a trailing / , a few images on the site disappear, w...

Which is the better way to simulate optional parameters in Java?

I have a Java method that takes 3 parameters, and I'd like it to also have a 4th "optional" parameter. I know that Java doesn't support optional parameters directly, so I coded in a 4th parameter and when I don't want to pass it I pass null. (And then the method checks for null before using it.) I know this is kind of clunky... but the o...

Optional parameters for interfaces

Using c# 4.0 -- building an interface and a class that implements the interface. I want to declare an optional parameter in the interface and have it be reflected in the class. So, I have the following: public interface IFoo { void Bar(int i, int j=0); } public class Foo { void Bar(int i, int j=0) { // do stuff } } ...

Optional parameters in Visual Studio 2008 Crystal Reports

I am developing a Crystal Report in Visual Studio 2008. I am trying to implement optional parameters so that a user does not have to specify a value or range for a particular field. Essentially, this means there is no filtering done on that field if the user wishes. However, I can't seem to figure out how to do this. Does anyone have a...

.Net 4.0, named and optional parameters, and WCF

so .Net 4 added named and optional params which are pretty sweet..I don't need to make as many 1 line overload methods. Will that work over WCF? ...

C# 4: conflicting overloaded methods with optional parameters

I have two overloaded methods, one with an optional parameter. void foo(string a) { } void foo(string a, int b = 0) { } now I call: foo("abc"); interestingly the first overload is called. why not the second overload with optional value set to zero? To be honest, I would have expect the compiler to bring an error, at least ...

Optional non-system type parameters

C#4.0 obviously brings optional parameters (which I've been waiting for, for quite some time). However it seems that because only system types can be const that I cannot use any class/struct which I have created, as an optional param. Is there a some way which allows me to use a more complex type as an optional parameter. Or is this on...

avoiding the tedium of optional parameters

If I have a constructor with say 2 required parameters and 4 optional parameters, how can I avoid writing 16 constructors or even the 10 or so constructors I'd have to write if I used default parameters (which I don't like because it's poor self-documentation)? Are there any idioms or methods using templates I can use to make it less te...

Cannot use String.Empty as a default value for an optional parameter in C# - then what's the point?

I am reading Effective C# by Bill Wagner. In Item 14 - Minimize Duplicate Initialization Logic, he shows the following example of using the new optional parameters feature in a constructor: public MyClass(int initialCount = 0, string name = "") Notice that he used "" instead of string.Empty. He comments: You'll note [in an example ...

How to make command-line options mandatory with GLib?

I use GLib to parse some command-line options. The problem is that I want to make two of those options mandatory so that the program terminates with the help screen if the user omits them. My code looks like this: static gint line = -1; static gint column = -1; static GOptionEntry options[] = { {"line", 'l', 0, G_OPTION_ARG_INT,...

Why isn't the new() generic constraint satisfied by a class with optional parameters in the constructor?

The following code fails to compile, producing a "Widget must be a non-abstract type with a public parameterless constructor" error. I would think that the compiler has all of the information it needs. Is this a bug? An oversight? Or is there some scenario where this would not be valid? public class Factory<T> where T : new() { publ...

copy constructor with default arguments

As far as I know, the copy constructor must be of the form T(const T&) or T(T&). What if I wanted to add default arguments to the signature? T(const T&, double f = 1.0); Would that be standards compliant? ...

C# 4.0: Can I use a Color as an optional parameter with a default value?

public void log(String msg, Color c = Color.black) { loggerText.ForeColor = c; loggerText.AppendText("\n" + msg); } This results in an error that c must be a compile-time constant. I've read up on this a little and most examples are dealing with strings and ints. I've figured out I can use the colorconver...

Passing optional parameter by reference in c++

I'm having a problem with optional function parameter in C++ What I'm trying to do is to write function with optional parameter which is passed by reference, so that I can use it in two ways (1) and (2), but on (2) I don't really care what is the value of mFoobar. I've tried such a code: void foo(double &bar, double &foobar = NULL) {...

C# 4.0 optional out/ref arguments

Does C# 4.0 allow optional out or ref arguments? ...

Optional Specification of some C# Optional Parameters

Suppose you have a method with the following signature: public void SomeMethod(bool foo = false, bool bar = true) { /* ... */ } When calling this method, is there a way to specify a value for bar and not foo? It would look something like... SomeMethod(_, false); ... which would translate to... SometMethod(false, false); ... at ...

Why optional parameters must appear at the end of the declaration

In all programming languages supporting optional parameters that I have seen there is a imitation that the optional parameters must appear at the end of the declaration. No required parameters may be included after an optional item. What is the reason for that ? I guess it can be compiler/interpreter requirement. ...