optional-parameters

Can't use optional parameters when implementing an interface for a WCF

徘徊边缘 提交于 2019-12-19 05:14:07
问题 In my interface I have declared this. [OperationContract] [WebGet] String GetStuff(String beep, String boop = "too lazy to type"); I implemented it as follows. String GetStuff(String beep, String boop = "too lazy to type") { ... } It compiles and uploads as my WCF service. However, when I used it as a web reference and try to execute the code below, I get the compiler whining and weeping about no method with signature of a single parameter. The last line is the problem. How can I then be too

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

萝らか妹 提交于 2019-12-18 09:42:34
问题 This question already has answers here : Why optional parameters must appear at the end of the declaration (6 answers) Closed 5 years ago . 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

Constructor does weird things with optional parameters [duplicate]

扶醉桌前 提交于 2019-12-18 04:39:16
问题 This question already has answers here : Closed 9 years ago . Possible Duplicate: least astonishment in python: the mutable default argument I want to understand of the behavior and implications of the python __init__ constructor. It seems like when there is an optional parameter and you try and set an existing object to a new object the optional value of the existing object is preserved and copied. Look at an example: In the code below I am trying to make a tree structure with nodes and

Are Options and named default arguments like oil and water in a Scala API?

六月ゝ 毕业季﹏ 提交于 2019-12-17 21:49:07
问题 I'm working on a Scala API (for Twilio, by the way) where operations have a pretty large amount of parameters and many of these have sensible default values. To reduce typing and increase usability, I've decided to use case classes with named and default arguments. For instance for the TwiML Gather verb: case class Gather(finishOnKey: Char = '#', numDigits: Int = Integer.MAX_VALUE, // Infinite callbackUrl: Option[String] = None, timeout: Int = 5 ) extends Verb The parameter of interest here

Passing optional parameter by reference in c++

大憨熊 提交于 2019-12-17 15:38:43
问题 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) { bar = 100; foobar = 150; } int main() { double mBar(0),mFoobar(0); foo(mBar,mFoobar); // (1) cout << mBar << mFoobar; mBar = 0; mFoobar = 0; foo(mBar); // (2)

Cannot use String.Empty as a default value for an optional parameter

亡梦爱人 提交于 2019-12-17 15:24:46
问题 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 above] that the second constructor specified "" for the default value on the name parameter, rather than the more customary string.Empty . That's because string

C# 4.0 optional out/ref arguments

孤街醉人 提交于 2019-12-17 04:47:31
问题 Does C# 4.0 allow optional out or ref arguments? 回答1: As already mentioned, this is simply not allowed and I think it makes a very good sense. However, to add some more details, here is a quote from the C# 4.0 Specification, section 21.1: Formal parameters of constructors, methods, indexers and delegate types can be declared optional: fixed-parameter: attributes opt parameter-modifier opt type identifier default-argument opt default-argument: = expression A fixed-parameter with a default

method overloading vs optional parameter in C# 4.0 [duplicate]

Deadly 提交于 2019-12-17 04:47:22
问题 This question already has answers here : Should you declare methods using overloads or optional parameters in C# 4.0? (13 answers) Closed 6 years ago . which one is better? at a glance optional parameter seems better (less code, less XML documentation, etc), but why do most MSDN library classes use overloading instead of optional parameters? Is there any special thing you have to take note when you choose to use optional parameter (or overloading)? 回答1: One good use case for 'Optional

Why are C# 4 optional parameters defined on interface not enforced on implementing class?

假如想象 提交于 2019-12-17 04:12:22
问题 I noticed that with the optional parameters in C# 4 if you specify a parameter as optional on an interface you DON'T have to make that parameter optional on any implementing class: public interface MyInterface { void TestMethod(bool flag = false); } public class MyClass : MyInterface { public void TestMethod(bool flag) { Console.WriteLine(flag); } } and therefore: var obj = new MyClass(); obj.TestMethod(); // compiler error var obj2 = new MyClass() as MyInterface; obj2.TestMethod(); // prints

C# optional parameters on overridden methods

送分小仙女□ 提交于 2019-12-17 03:04:06
问题 Seems like in .NET Framework there is an issue with optional parameters when you override the method. The output of the code below is: "bbb" "aaa" . But the output I'm expecting is: "bbb" "bbb" .Is there a solution for this. I know it can be solved with method overloading but wondering the reason for this. Also the code works fine in Mono. class Program { class AAA { public virtual void MyMethod(string s = "aaa") { Console.WriteLine(s); } public virtual void MyMethod2() { MyMethod(); } }