16 EKİM 2010, CUMARTESİ
C# 4.0, isteğe bağlı parametreler ve parametreler birlikte çalışmıyor
Nasıl isteğe bağlı parametre vardır ve birlikte kullanımı olan bir yöntem oluşturabilir miyim?
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[] C)
{
Console.WriteLine(A);
Console.WriteLine(B);
Console.WriteLine(C.Count());
}
CEVAP
9 ŞUBAT 2011, ÇARŞAMBA
Tek seçenek şu an aşırı TestOptional C# 4 önce yapman gereken gibi). Tercih ederim, ama kullanım noktasında kodu temizler.
public static void TestOptional(string A, params string[] C)
{
TestOptional(A, 0, C);
}
public static void TestOptional(string A, int B, params string[] C)
{
Console.WriteLine(A);
Console.WriteLine(B);
Console.WriteLine(C.Count());
}
Bunu PaylaÅŸ:

Java isteğe bağlı parametreler...
Neden C# 4 isteğe bağlı parametreler a...
Javascript kullanma isteğe bağlı param...
Nasıl T-SQL saklı yordam isteğe bağlı ...
Ruby isteğe bağlı parametreler...