#1
  1. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2004
    Posts
    174
    Rep Power
    0

    Post Converting C++ to C# that cannot be assigned


    Hey all I am translating some C++ code over to C# and I am at a stopping place due to an error that I cant seem to figure out:

    My c# code:
    Code:
    public static String inputStr;
    public static int inputLength;
    
    public static void inputCheck()
    {
        inputLength = inputStr.Length;
        int i = 0;
    
        while (i < inputLength) {
           if (inputStr[i] > 95 && inputStr[i] < 123) {
               inputStr[i] -= 32;
           }
    
           i++;
        }
    }
    The error is on this line:
    inputStr[i] -= 32;
    And its saying:

    Error CS0200 Property or indexer 'string.this[int]' cannot be assigned to -- it is read only
    Any help would be great as I'm not sure why I am even getting an error like that.
  2. #2
  3. Backwards Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    16,914
    Rep Power
    9646
    C# strings are immutable - you can't change them.

    Use StringBuilder.

IMN logo majestic logo threadwatch logo seochat tools logo