I am coming from c++ and its nice STL. In C++ I could do this

<include> string

int nMyInt = 5;
string sMyString;
sMyString[5] = "b";

Ive tried this approach in c# but doing this way gives me this error

Property or indexer 'string.this[int]' cannot be assigned to -- it is read only

And I understand the error... is there anyway to do this in C#??

String is immutable (constant/readonly)object. Its value cannot be modified once it has been created.

Use StringBuilder class (It's mutable object).

StringBuilder sb = new StringBuilder();
sb[3] = 'l';
commented: Thanks So Much +1
Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.18 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.