optional-parameters

Using an optional parameter of type System.Drawing.Color

I am starting to take advantage of optional parameters in .Net 4.0 The problem I am having is when I try to declare an optional parameter of System.Drawing.Color: public myObject(int foo, string bar, Color rgb = Color.Transparent) { // .... } I want Color.Transparent to be the default value for the rgb param. The problem is, I k...

Default method parameters In C#

How i can make the method have a default values for parameters ? ...

Why is generated override code for generic method incorrect?

I have an abstract generic class public abstract class Foo<TType> with an abstract method public abstract object DoSomething(TType arg = default(TType)) {} Now, the inherited class public class BabyFoo : Foo<string> when I want to override DoSomething and start typing "override " to get the intellisense/generator to write a meth...

difference between default and optional arguments

okay code: #!/usr/bin/python import wx import sys class XPinst(wx.App): def __init__(self, redirect=False, filename=None): wx.App.__init__(self, redirect, filename) def OnInit(self): frame = wx.Frame(None, -1, title='Redirect Test', size=(620,450), style=wx.STAY_ON_TOP|wx.DEFAULT_FRAME_STYLE) panel = wx...

Find all optional parameters and remove them

Having used optional parameters in a few classes here and there, I'm starting to dislike them immensely for the trouble they cause in certain cases with overload resolution, i.e. difficulties in binding delegates to them due to signature conflicts, as well as dynamic invocation problems with regard to method argument count. How can I se...

C# Default Parameters

This is, probably, a very simple answer for someone. I have a method with an Optional Parameter like so; public static Email From(string emailAddress, string name = "") { var email = new Email(); email.Message.From = new MailAddress(emailAddress, name); return email; } Now, I must target .Net 3.5 and i...

C# 4.0 - How to Handle Optional String Parameters

This code is not valid: private void Foo(string optionalString = string.Empty) { // do foo. } But this code is: private void Foo(string optionalString = "") { // do foo. } Why? Because string.Empty is a readonly field, not a constant, and defaults for optional parameters must be a compile-time constant. So, onto my question....

Adding parameters to Runtime.getRuntime() ??

void restartWeb() { try { String[] command = new String[] {"webRestarter.exe" , ">>","webLog.log"}; Runtime.getRuntime().exec(command); } catch (java.io.IOException err) { webServer.logError(err.getMessage()); } } Why doesn't this work? How could I fix it so it does work like ...

C# optional arguments in abstract method

Given: interface IFoo { void Print(string text = "abc"); } class Bar : IFoo { public void Print(string text = "def") { Console.WriteLine(text); } } class Program { static void Main(string[] args) { Bar b = new Bar(); b.Print(); IFoo f = b as IFoo; f.Print(); } } Th...

Can a Delegate have an optional parameter?

I have the below code that was working fine until I tried adding the bool NetworkAvailable = true portion. Now I get a Method name expected compile time exception at Line 4 below. void NetworkStatus_AvailabilityChanged(object sender, NetworkStatusChangedArgs e) { var networkAvailable = e.IsAvailable; SetUpdateHUDConnectedMode d =...

Passing null to an optional parameter with default value

I think this is a pretty basic question, but I just want to clarify. If I have a variable with a null value, and pass it as a parameter that is optional, will the parameter get the null value, or the default value? dim str As String = "foo" dim obj As Object //call 1 Request(str, str) //call 2 Request(str) //call 3 Request(str, obj) ...

C# 4.0, optional parameters and params do not work together

How can i create a method that has optional parameters and params together? static void Main(string[] args) { TestOptional("A",C: "D", "E");//this will not build TestOptional("A",C: "D"); //this does work , but i can only set 1 param Console.ReadLine(); } public static void TestOptional(string A, int B = 0, params string[...

PHP Optional Parameters - specify parameter value by name?

Hey, I was just wondering... I know it is possible to use optional arguments as follows: function doSomething($do, $something = "something") { } doSomething("do"); doSomething("do", "nothing"); But suppose you have the following situation: function doSomething($do, $something = "something", $or = "or", $nothing = "nothing") { } ...

Optional method arguments in C++, but from the callee's side?

In C++ methods can have optional arguments, like this: void myFunction (int arg1, int arg2=0); In this case myFunction can be called with 1 integer or with two. If you omit the second integer, the value 0 is passed instead. I am now looking for ways to obtain the same functionality, but from the callee's side. Suppose I have an int...