How to print braces {} in C#

Lionsure 2020-09-19 Original by the website

The brace is a special character in C#. It cannot be input like ordinary characters, nor can it be print with a transfer character(\). Instead, it should be print like this {{}}. The following is a specific example:


Output Javascript code in C#

Aspx file:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="outputdakuohao.aspx.cs" Inherits="testpro.utputdakuohao" %>
<!DOCTYPE html>
<head runat="server">
       <title>How to print braces in C#</title>
       <form id="form1" runat="server">
                     <asp:Literal ID="test" runat="server" />


CS file:

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('Print braces!');}}output();</script>";

After passing the test in Visual Studio. create a new file, copy the code into it, and run it directly.