我在一个 WebForm 中,我想使用这种格式的通用 Console.Writeline:
Console.WriteLine("{0}{1}:", myString, myProp);
使用 Response.Write(将代码放在客户端)。我可以吗?
在这种情况下使用 ofConsole.WriteLine("{0}{1}:", myString, myProp);
没有意义,但您可以使用以下string.Format()
方法:
Response.Write(string.Format("{0}{1}:", myString, myProp));
您可以编写一个方法,例如
public static void WriteToResponse(string format, params object[] args)
{
Response.Write(String.Format(format, args));
}
上面的方法Console
相当于Console.Write
你可以添加一个额外Response.Write(Environment.NewLine)
的,使其类似于Console.WriteLine
public static void WriteLineToResponse(string format, params object[] args)
{
Response.Write(String.Format(format, args));
Response.Write(Environment.NewLine);
}
您可以使用:
Response.Write (string.Format("{0}{1}:", myString, myProp));
或者为 Response.Write 创建一个扩展方法,使用字符串、object[] 作为参数。