如何转换类型';字符串';至';字符串[]和#x27;在c#中?

如何转换类型';字符串';至';字符串[]和#x27;在c#中?,c#,xna,C#,Xna,我的代码有点问题,请您帮助: String[] Boe; Boe = new String[1]; <---- i think the error might also be here BS = new Rectangle(); for (int p = 0; p < 1; p++) { //some code have been taken out

我的代码有点问题,请您帮助:

         String[] Boe;

         Boe = new String[1]; <---- i think the error might also be here 
         BS = new Rectangle();
         for (int p = 0; p < 1; p++)
         {
           //some code have been taken out 

             Boe = "Yes"; <----- this is where the error is being displayed 
         }
String[]Boe;

Boe=新字符串[1] 代码的问题在于,您试图将整个数组设置为一个简单的字符串。您必须访问数组的索引,然后给这个位置一个字符串值。 看看下面

 String[] Boe;
 Boe = new String[1]; <---- i think the error might also be here 
 BS = new Rectangle();
 for (int p = 0; p < 1; p++)
 {
   //some code have been taken out 

     Boe[p] = "Yes"; <----- this is where the error is being displayed 
 }
String[]Boe;

Boe=新字符串[1]
Boe[0]=“Yes”
,这里真的不需要
for
循环。在这种情况下,我给了你一个for循环,但是@AndrejBratoz只给你索引器0是正确的,因为你只有一个值。由于在for循环结束时,您将再次检查是否仍在范围内,因此会损失一些性能。如果示例代码只是一个示例,并且您可能在不久的将来需要它,那么就给出了循环。