logo search
Учебник_ПОА

Имитация параметров по умолчанию

В этом примере демонстрируется использование перегрузки метода для имитации параметров по умолчанию.

Пример

class MyClass

{

static string myMethod(string precip, string country, string location)

{

return string.Format("The {0} in {1} stays mainly in the {2}.",

precip, country, location );

}

static string myMethod(string precip, string country )

{

return myMethod(precip, country, "plain");

}

static string myMethod()

{

return myMethod("rain", "Spain", "plain");

}

static void Main(string[] args)

{

System.Console.WriteLine(myMethod());

System.Console.WriteLine(myMethod("snow", "Walla Walla"));

}

}