1
Reply

string assigning error

Sudheer Kumar

Sudheer Kumar

Dec 20 2017 8:28 AM
135
with the below code i am getting an error as Property or indexer 'string.this[int]' cannot be assigned to -- it is read only
 
 can some one explain why? 
public class Program
{
static void Main(string[] args)
{
string userName = "Joey";
GreetUser(userName);
Console.WriteLine(userName);
}
public static void GreetUser(string userName)
{
userName[0] = 'm'; //line1
char c = userName[0]; //line2
userName = "Hello" + userName; //line3
}
}

Answers (1)