在C#中并沒(méi)有printf函數(shù),但可以使用Console.WriteLine方法進(jìn)行類似的功能。此方法接受一個(gè)字符串參數(shù),用于格式化輸出。
以下是一些參數(shù)傳遞技巧:
int x = 10;
string name = "Alice";
Console.WriteLine("Value of x: {0}, Name: {1}", x, name);
double value = 3.14159;
Console.WriteLine("Value: {0,-10:F2}", value);
int age = 25;
string message = $"My age is {age}";
Console.WriteLine(message);
string multiLineString = @"
Line 1
Line 2
Line 3";
Console.WriteLine(multiLineString);