只要在字串開頭加上$,在字串內用{變數},會以便數值取代。可沿用既有的格式化字串符號
public static void Main(string[] args)
{
string FirstName = "John";
string LastName = "Lin";
double PI = 3.141596825;
DateTime date = DateTime.Now;
string FullName = $"{FirstName} {LastName} {PI:f2} {date:yyyy-MM-dd}";
Console.WriteLine(FullName);
}
沒有留言:
張貼留言