C#怎么输出大括号{}
在 C# 中,大括号作为一个特殊字符,不能像普通字符一样输入,也不能加转议字符(\)输出,而是要这样输出 {{}},下面是具体实例:
在 C# 输出 Javascript 代码
aspx 文件:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="outputdakuohao.aspx.cs" Inherits="testpro.outputdakuohao" %>
<!DOCTYPE html>
<html>
<head runat="server">
<title>C#怎么输出大括号</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Literal ID="test" runat="server" />
</div>
</form>
</body>
</html>
CS 文件:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace testpro
{
public partial class outputdakuohao : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
test.Text = "<script type='text/javascript'>function output(){{alert('输出大括号!');}}output();</script>";
}
}
}
经 VS2010 测试通过,新建一个文件,把代码复制进去,可直接运行。