Search code examples
c#xna

how to convert type 'string' to 'string[]' in c#?


i have a bit of a problem with my code please can you help:

         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 
         }

Solution

  • The problem with your code is that your trying to set the whole array as a simple string. You have to access the index of your array and then give this position a string value. Look down there

     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 
     }
    

    Hope it helps you !