stringbuilder类型数组 [英] stringbuilder type array

查看:118
本文介绍了stringbuilder类型数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好
我在做

hello
i am making

StringBuilder[] builder = new StringBuilder[pin];
       for (int i = 0; i < pin; i++)
       {
           
           string random = GetRandomNumbers(3);
           string guid = GetRandom(6);

           builder[i].Append(plan);
           int mnth = DateTime.Now.Month;
           int year = DateTime.Now.Year;
           builder[i].Append(Convert.ToString(mnth));
           builder[i].Append(Convert.ToString(year));
           builder[i].Append(guid);
}
return builder;


但是它抛出错误"System.IndexOutOfRangeException:索引超出了数组的边界"

在线


but it is throwing error " System.IndexOutOfRangeException: Index was outside the bounds of the array"

on line

builder[i].Append(plan);


有人能说出问题吗?


can some one tell wats the problem

推荐答案

您需要为数组的每个元素分配一个新的StringBuilder:
You need to allocate a new StringBuilder to each element of the array:
StringBuilder[] builder = new StringBuilder[pin];
for (int i = 0; i < pin; i++)
{
    string random = GetRandomNumbers(3);
    string guid = GetRandom(6);
    builder[i] = new StringBuilder();
    builder[i].Append(plan);


这篇关于stringbuilder类型数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆