optional-parameters

C# Selecting a different method to the one expected with optional parameters and multiple levels of inheritance

大兔子大兔子 提交于 2019-12-22 13:55:37
问题 In the given example (sorry for code style, it was in the interest of a compact self-contained repro), the method called is always the virtual method in B that has the additional integer parameter, while I would expect that the method implemented in C would be the one called. using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace MethodChoosing { class Program { static void Main(string[] args) { C c = new C(); c.M(); Console.ReadKey(); } } public class

Optional argument followed by Params [duplicate]

被刻印的时光 ゝ 提交于 2019-12-22 03:19:14
问题 This question already has answers here : C# 4.0, optional parameters and params do not work together (3 answers) Closed 6 years ago . So I see that it's possible to have a method signature where the first parameter provides a default value and the second parameter is a params collection. What I can't see is a way to actually use the default value of the first argument. Is it at all possible? Example method: void WaitAllTasks(string message = "Running Task.WaitAll", params Task[] tasks); I

Mutually exclusive powershell parameters

杀马特。学长 韩版系。学妹 提交于 2019-12-22 01:32:49
问题 SCENARIO I'm writing a cmdlet for Powershell 2.0 using Visual Studio 2008 and .NET 3.5 the cmdlet requires 3 arguments. my intended grammar of the cmdlet is something like this: cmdletname [foo|bar] p1, p2 That reads as the user must give a value for "-foo" or "-bar" but can't give both together. EXAMPLE OF VALID INPUT cmdletname -foo xxx -p1 hello -p2 world cmdletname -bar yyy -p1 hello -p2 world EXAMPLE OF INVALID INPUT cmdletname -foo xxx -bar yyy -p1 hello -p2 world MY QUESTION My

Websphere Application Server 6.1 (localized): Override locale for console messages

蓝咒 提交于 2019-12-21 17:44:02
问题 I have installed RAD 7.5 (based on Eclipse Ganymede 3.4.0) in Spanish. I'm working with Websphere Application Server 6.1 (spanish too). The problem I have is that all console messages appear in Spanish, but translation is, in my personal opinion, quite poor (especially since even the console errors are displayed in Spanish and it's difficult to find documentation about exact error messages). I want to start the IDE in the original language (English) and I know that there is a command line

Optional parameters and option types using F#

梦想的初衷 提交于 2019-12-21 07:12:10
问题 Consider the following code: type Test () = member o.fn1 (?bo) = 1 member o.fn2 (?bo) = o.fn1 bo member o.fn3 (?bo) = 1 + bo.Value member o.fn4 (?bo) = o.fn3 bo While fn1 and fn2 work just fine, fn4 produces the following error: init.fsx(6,30): error FS0001: This expression was expected to have type int but here has type 'a option MSDN states: Optional parameters are interpreted as the F# option type, so you can query them in the regular way that option types are queried, by using a match

C# - Calling a struct constructor that has all defaulted parameters

假装没事ソ 提交于 2019-12-20 17:35:54
问题 I ran into this issue today when creating a struct to hold a bunch of data. Here is an example: public struct ExampleStruct { public int Value { get; private set; } public ExampleStruct(int value = 1) : this() { Value = value; } } Looks fine and dandy. The problem is when I try to use this constructor without specifying a value and desiring to use the defaulted value of 1 for the parameter: private static void Main(string[] args) { ExampleStruct example1 = new ExampleStruct(); Console

Groovy method with optional parameters

微笑、不失礼 提交于 2019-12-20 10:22:04
问题 I would like to write a wrapper method for a webservice, the service accepts 2 mandatory and 3 optional parameters. To have a shorter example, I would like to get the following code working def myMethod(pParm1='1', pParm2='2') { println "${pParm1}${pParm2}" } myMethod(); myMethod('a') myMethod(pParm2:'a') // doesn't work as expected myMethod('b','c') The output is: 12 a2 [pParm2:a]2 a2 bc What I would like to achieve is to give one parameter and get 1a as the result. Is this possible (in the

Optional parameters for interfaces

不打扰是莪最后的温柔 提交于 2019-12-20 09:11:25
问题 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 } } This compiles, but it doesn't look right. The interface needs to have the optional parameters, because otherwise it doesn't reflect correctly in the interface method signature.

Segmentation fault with optional arguments in Fortran functions

不羁岁月 提交于 2019-12-19 07:06:30
问题 I can use Fortran optional argumenrs with subroutines with intent(in) and intent(inout) , but with functions optional arguments work only with intent(in) , right? With intent(inout) I get segmentation faults in the following code: real function foo(x, tol) real, intent(in) :: x real, optional, intent(inout) :: tol if( .not. present(tol) ) tol = 1e-6 !... end function foo 回答1: I found the problem, I used the variable even when not present on the fourth line (in tol = 1e-6 ): real function foo

Default method parameters in C#

时间秒杀一切 提交于 2019-12-19 05:24:18
问题 How can I make a method have default values for parameters? 回答1: A simple solution is to overload the method: private void Foo(int length) { } private void Foo() { Foo(20); } 回答2: You can only do this in C# 4, which introduced both named arguments and optional parameters: public void Foo(int x = 10) { Console.WriteLine(x); } ... Foo(); // Prints 10 Note that the default value has to be a constant - either a normal compile-time constant (e.g. a literal) or: The parameterless constructor of a