-7
string A = "myString";

string B;

Is there a way to initiate B according to the data of A, so that value B changes with A.

B = capture change of A?

Edit: My initial post was not complete and misleading, I found the answer now. Still my question is a duplicate of observer pattern

baci
  • 2,528
  • 15
  • 28

3 Answers3

7

Try this

B = A.Substring(0,2);

It initates B with substring of A from index 0 and lenght of 2

Kamil Budziewski
  • 22,699
  • 14
  • 85
  • 105
1

Sure, using String.Substring:

B = A.Substring(0,2);  //"my"
D Stanley
  • 149,601
  • 11
  • 178
  • 240
1

You can try the following example

string A = "myString";
string B;

if (A.StartsWith("my"))
{
    B = A.Substring(0, 2);//first two elements of A
}

Check out this Substring method

Navnath Godse
  • 2,233
  • 2
  • 23
  • 32