String[]的问题

闪光的小虫子 2003-10-18 03:43:43
String[] mystr;
foreach(string str1 mystr)
textBox2.AppendText(str1 + "\n");
能不能不用循环,一次就把string[]的内容全部传给textBox?
...全文
50 19 打赏 收藏 转发到动态 举报
写回复
用AI写文章
19 条回复
切换为时间正序
请发表友善的回复…
发表回复
Stevetan81 2003-10-29
  • 打赏
  • 举报
回复
great
xixigongzhu 2003-10-29
  • 打赏
  • 举报
回复
对了,换成"\r\n"试试
honghaozi 2003-10-29
  • 打赏
  • 举报
回复
大家在讨论什么?
用循环怎么都可以,
但楼主不让用循环啊。

楼上几位:foreach也是循环
qqq123 2003-10-28
  • 打赏
  • 举报
回复
"\n" -> "\r\n"
闪光的小虫子 2003-10-28
  • 打赏
  • 举报
回复
string[] str=new string[50];
for(int i=0;i<50;i++)
{
str[i]=i.ToString();
}
textBox1.Text=string.Join("\n",str);
join后的字符串的确变成了"1\n2\n3\n......"的形式
问题是把它传给textBox后"\n"并没有起到回车的作用,显示的字符串整个连在了一起
怎么回事呢?
xixigongzhu 2003-10-20
  • 打赏
  • 举报
回复
错了,是Join方法:
this.textBox2.Text = String.Join("\n", mystr);
xixigongzhu 2003-10-20
  • 打赏
  • 举报
回复
this.textBox2.Text = String.Concat("\n", mystr);
honghaozi 2003-10-20
  • 打赏
  • 举报
回复
那位老兄希望“不用循环”
houlinghouling 2003-10-20
  • 打赏
  • 举报
回复
做了个例子你看一看:(是可以远行的)
string[] str ;
str = new string[50];
for (int i =0;i<50;i++)
{
str[i]=i.ToString();
}

foreach (string mystr in str)
{
this.TextBox1.Text+=mystr+"\n ";
}
herofyf 2003-10-20
  • 打赏
  • 举报
回复
dldl(403) ( ) 你不就已经用了循环的吗!
在我看来好象不行!
dldl 2003-10-20
  • 打赏
  • 举报
回复
当然可以了!
1、你要把this.textBox1.Multiline = true;
2、string[] demo=new string[4];
demo[0]="oooo";
demo[1]="1111";
demo[2]="2222";
demo[3]="3333";
foreach(string str in demo)
{
this.textBox1.AppendText("\r\n"+str);
}
看看吧!
闪光的小虫子 2003-10-20
  • 打赏
  • 举报
回复
textBox2.Text=mystrs.toString();好像不行啊
eyoexply 2003-10-18
  • 打赏
  • 举报
回复
我之知道少了一个in
honghaozi 2003-10-18
  • 打赏
  • 举报
回复
不能
FileNewExit 2003-10-18
  • 打赏
  • 举报
回复
daou101(海天一鸥) 似乎说得不对吧:<
请看:

using System;

class Test{
public static void Main(){
string[] str = new string[4];
for(int i = 0; i < str.Length; i++)
str[i] = i.ToString();
string str2 = str.ToString();
Console.WriteLine(str2);
}
}

编译后输出为:
System.String[]
并非daou101(海天一鸥)所期望的那样
MyLf 2003-10-18
  • 打赏
  • 举报
回复
数组没有那样的方法吧。用循环很麻烦吗?
你写错了。
foreach(string str1 in mystr)
textBox2.AppendText(str1 + "\n");

.toString()只是返回对数组的对象字符串。
daou101 2003-10-18
  • 打赏
  • 举报
回复
of course Not , U can use const String to do that , means your string cann't to be modified
---------------------------------------------------------------------------------
string is not String;
string is type of var,but String is static class;
you can do:
string[] mystrs[];
………………//init mystrs;
textBox2.Text=mystrs.toString();


elite2018 2003-10-18
  • 打赏
  • 举报
回复
of course Not , U can use const String to do that , means your string cann't to be modified
rgbcn 2003-10-18
  • 打赏
  • 举报
回复
好像不行吧。

110,499

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧