gpt4 book ai didi

c# - 使用未分配的局部变量 "strb"StringBuilder

转载 作者:太空宇宙 更新时间:2023-11-03 19:55:08 24 4
gpt4 key购买 nike

<分区>

所以我正在尝试学习如何使用 StringBuilder 类。我阅读了它,与 string 相比,它看起来很棒!

我正在尝试在另一个按钮中创建 StringBuilder 但它一直向我抛出错误:

; expected" and Use of unassigned local variable "strb"

第 42 和 43 行。

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApplication15
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
string nrmlString = "C#";
nrmlString += " This";
nrmlString += " is";
nrmlString += " a";
nrmlString += " Test";
nrmlString += " Thisss";

MessageBox.Show(nrmlString);
}

private void button2_Click(object sender, EventArgs e)
{
StringBuilder strb new StringBuilder("something");
strb.Append("Something else");
MessageBox.Show(strb.ToString());
}
}
}

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com