Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
List 显示列表中的文本_List_Text - Fatal编程技术网

List 显示列表中的文本

List 显示列表中的文本,list,text,List,Text,我试图在一个字符串列表的文本区域中显示几行。但它只显示列表中的最后一个,我想全部显示。谢谢你的帮助 using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class contenuTexte : MonoBehaviour { public List <string> montex

我试图在一个字符串列表的文本区域中显示几行。但它只显示列表中的最后一个,我想全部显示。谢谢你的帮助

using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using UnityEngine.UI;


    public class contenuTexte : MonoBehaviour {
    public List <string> montexte;
    public GameObject zoneAffichage;



        // Update is called once per frame
        void Start ()
        {



            foreach ( string lines in montexte)
                zoneAffichage.GetComponent<Text>().text = "\n"+lines;

            }



        }
使用系统集合;
使用System.Collections.Generic;
使用UnityEngine;
使用UnityEngine.UI;
公共类上下文:单一行为{
蒙特克斯特公开名单;
公共游戏对象分区办公室;
//每帧调用一次更新
无效开始()
{
foreach(montext中的字符串行)
zoneAffichage.GetComponent().text=“\n”+行;
}
}

您的问题是您正在将每个循环上的字符串重置为最后一个字符串。在循环结束时,文本中只有最后一个字符串

首先,让我们将所有字符串合并为一个字符串(由于.NET 3.5的原因,使用.ToArray()),然后立即设置它们:

var completeText = String.Join("\n", montexte.ToArray());

zoneAffichage.GetComponent<Text>().text = completeText;
var completeText=String.Join(“\n”,montext.ToArray());
zoneAffichage.GetComponent().text=completeText;

您的问题是您正在将每个循环上的字符串重置为最后一个字符串。在循环结束时,文本中只有最后一个字符串

首先,让我们将所有字符串合并为一个字符串(由于.NET 3.5的原因,使用.ToArray()),然后立即设置它们:

var completeText = String.Join("\n", montexte.ToArray());

zoneAffichage.GetComponent<Text>().text = completeText;
var completeText=String.Join(“\n”,montext.ToArray());
zoneAffichage.GetComponent().text=completeText;

非常感谢!但是我遇到了编译器错误:“与
string.Join(string,string[])匹配的最佳重载方法“有一些无效的参数”,并且参数
#2'无法转换
System.Collections.Generic.List'expression to type
string[]”@tieum67啊,我的错,我假设你的.NET版本是>4,但你必须在.NET 3.5左右。我会修正我的答案,修正版本的。内特汉克斯很多!但是我遇到了编译器错误:“与
string.Join(string,string[])匹配的最佳重载方法“有一些无效的参数”,并且参数
#2'无法转换
System.Collections.Generic.List'expression to type
string[]”@tieum67啊,我的错,我假设你的.NET版本是>4,但你必须在.NET 3.5左右。我将针对该版本的.NET更正我的答案