I write the code to scramble word I am create simple game jumble
string jumble = theWord;
int length = jumble.Count();
for (int i = 0; i < length; ++i)
{
int index1 = (rand.Next() % length);
int index2 = (rand.Next() % length);
char temp =jumble[index1];
jumble = jumble.Replace(jumble[index1], jumble[index2]);
jumble = jumble.Replace(jumble[index1], temp);
}
update the code
string jumble = theWord;
int length = jumble.Count();
for (int i = 0; i < length; ++i)
{
int index1 = (rand.Next() % length);
//int index2 = (rand.Next() % length);
char temp = jumble[index1];
jumble[i] = jumble[index1 - 1];
jumble[i] = temp;
}
Error 1 Property or indexer ‘string.this[int]’ cannot be assigned to
— it is read only
1 Answer