函数重载写法
using System;
public static class TwoFer
{
// In order to get the tests running, first you need to make sure the Speak method
// can be called both without any arguments and also by passing one string argument.
public static string Speak()
{
return "One for you, one for me.";
}
public static string Speak(string name)
{
return String.Format("One for {0}, one for me.", name);
}
}
更优雅的字符串格式化写法:
using System;
public static class TwoFer
{
// In order to get the tests running, first you need to make sure the Speak method
// can be called both without any arguments and also by passing one string argument.
public static string Speak()
{
return "One for you, one for me.";
}
public static string Speak(string name)
{
return $"One for {name}, one for me.";
}
}
默认参数 + Lambda表达式写法:
using System;
public static class TwoFer
{
// In order to get the tests running, first you need to make sure the Speak method
// can be called both without any arguments and also by passing one string argument.
public static string Speak(string person = "you") => $"One for {person}, one for me.";
}