optional-parameters

Using an enum as an optional parameter

孤街醉人 提交于 2019-11-30 08:14:33
I have several methods in an application I'm working on loaded with optional parameters, some of which are enums. Currently, in order to do that I'm writing methods with a similar type of signature: public void SomeMethod(string myFirstParam = "", string mySecondParam = "", MyEnum myThirdParam = (MyEnum )(-1)){ if (myThirdParam != (MyEnum ) (-1)) { //do something with it } } So my first question is, is there some pitfall to this approach I haven't realized, but in time will become painfully aware of, and secondly, is there a more proper - or at least elegant solution to it? I should say that

Named/optional parameters in Delphi?

余生长醉 提交于 2019-11-30 08:06:31
问题 In one of the Delphi demo applications, I've stumbled upon some syntax that I didn't know the Delphi compiler accepted: // ......\Demos\DelphiWin32\VCLWin32\ActiveX\OleAuto\SrvComp\Word\ // Main.pas, line 109 Docs.Add(NewTemplate := True); // note the assignment I can't seem to reproduce this type of parameter passing in my own code, and I never see anyone use it. So these are my questions: Can i use this in "normal" methods and is it part of "the Delphi Language", or is this some compiler

C# Default Parameters

北战南征 提交于 2019-11-30 06:57:33
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 it was my understanding that Optional Parameters are part of .Net 4. However, my project builds and I double checked the Properties - Application page which states 3.5 as the target framework. Then I found a article on MSDN saying it's a feature of C#4 in VS2010. ( MSDN Article --> Named and

Optional parameters in Python functions and their default values [duplicate]

≯℡__Kan透↙ 提交于 2019-11-30 05:40:28
Possible Duplicate: “Least Astonishment” in Python: The Mutable Default Argument I'm kind of confused about how optional parameters work in Python functions/methods. I have the following code block: >>> def F(a, b=[]): ... b.append(a) ... return b ... >>> F(0) [0] >>> F(1) [0, 1] >>> Why F(1) returns [0, 1] and not [1] ? I mean, what is happening inside ? Good doc from PyCon a couple years back - Default parameter values explained . But basically, since lists are mutable objects, and keyword arguments are evaluated at function definition time, every time you call the function, you get the same

How to provide default value for a parameter of delegate type in C#?

本小妞迷上赌 提交于 2019-11-30 03:03:53
问题 In C# we can provide default value of the parameters as such: void Foo(int i =0) {} But, when the method signature is: void FooWithDelegateParam(Func<string,string> predicate) {} How can we pass the default parameter: void FooWithDelegateParam(Func<string,string> predicate = (string,string x)=> {return y;}) {} But this won't compile. So, what is the proper syntax for doing so ? Note: I'm trying to provide a way to specify an input-string to output-string mapper through a delegate, and if not

Passing in NULL as a parameter in ES6 does not use the default parameter when one is provided

痴心易碎 提交于 2019-11-30 02:41:15
Is there a known reason why passing in null as a parameter in ES6 does not use the default parameter when one is provided? function sayHello(name = "World") { console.log("Hello, " + name + "!"); } sayHello("Jim"); // Hello, Jim! sayHello(undefined); // Hello, World! sayHello(null); // Hello, null! This is not that obvious I've read some comments of why undefined is completely different than null and that's why it explains the current behavior of default parameters. One could argue that explicitly passing undefined should not trigger the default value substitution because when I have a

The compiler is complaining about my default parameters?

你。 提交于 2019-11-29 22:08:28
I'm having trouble with this piece of code , after i took this class from the main.cpp file and splitted it in to .h and .cpp the compiler started complaining about the default parameters i was using in a void. /* PBASE.H */ class pBase : public sf::Thread { private: bool Running; public: sf::Mutex Mutex; WORD OriginalColor; pBase(){ Launch(); Running = true; OriginalColor = 0x7; } void progressBar(int , int); bool key_pressed(); void setColor( int ); void setTitle( LPCWSTR ); bool test_connection(){ if(Running == false){ return 0; } else{ return 1; } return 0; } void Stop(){ Running = false;

optional parameters must appear after all required parameters in c# [duplicate]

半城伤御伤魂 提交于 2019-11-29 18:49:17
This question already has an answer here: Why optional parameters must appear at the end of the declaration 6 answers Method 1 public List<IndentItems> GetIndentsByStatus(string projectAddress, string jobAddress, string currentStatus,string ddlevent) { List<IndentItems> indentItems =null; indentItems = GetIndentFilledInfo(filterdReports, false,null ,ddlevent); return indentItems; } Method 2 public List<IndentItems> GetIndentFilledInfo(List<SurveyFeedback> surveyFeedbacks, bool hasupdate, string indentType = null,string ddlevent) { } From Method1 I'm calling the second method and in method2

System.MissingMethodException after adding an optional parameter

ⅰ亾dé卋堺 提交于 2019-11-29 16:19:39
问题 I am getting error of System.MissingMethodException after I have an optional parameter in one component and the other component which call it was not build as it call it with old number of parameters. Only component in which parameter is added was build an deployed as patch. The calling component is old as there is no change in it. When the calling component run it gives error : Exception Information Exception Type: System.MissingMethodException Message: Method not found: 'LabelURLs IPSD.BnB

Optional parameters on delegates doesn't work properly [duplicate]

青春壹個敷衍的年華 提交于 2019-11-29 15:03:35
This question already has an answer here: Can a Delegate have an optional parameter? 2 answers Why this piece of code does not compile? delegate int xxx(bool x = true); xxx test = f; int f() { return 4; } Optional parameters are for use on the calling side - not on what is effectively like a single-method-interface implementation . So for example, this should compile: delegate void SimpleDelegate(bool x = true); static void Main() { SimpleDelegate x = Foo; x(); // Will print "True" } static void Foo(bool y) { Console.WriteLine(y); } What will happen test(false) ? It will corrupt the stack,