public string[] arrTestResults = new string[8];
public string TestName;
[TestInitialize]
public void SetupTest()
{
// Assigning aliases to array indexes
TestName = arrTestResults[0] = "";
}
public void General()
{
arrTestResults[0] = "Test 1: General"; // works
TestName = "Test 1: General"; // does not work. Quick Watch says TestName = Null. WHY?
public string[] arrTestResults = new string[8]; public string TestName; [TestInitialize] public void SetupTest() {
Share
TestNameis NOT an alias toarrTestResults[0].I’m assuming that
arrTestResultsisstring[]and thatTestNameis too.arrTestResults[0]is a storage location whose value refers to an instance ofstring.TestNameis a storage location whose value refers to an instance ofstring.does not make
TestNamean alias forarrTestResults[0]. Instead, it assigns to the storage locationTestNameand to the storage locationarrTestResults[0]a reference to an instance ofstringthat is equal to"". That is, there is a reference to"". That reference is assigned toarrTestResults[0]and toTestName. It is quite similar toHere,
xis NOT an alias fory. We have just copied the value17toyand tox. In our case, the value is the reference. A reference to""is copied toarrTestResults[0]and toTestName.Then
assigns a new reference to the storage location
arrTestResults[0].It’s quite like
And then
assigns a new reference to the storage location
TestName. It does not alter the value ofarrTestResults[0]because these two storage locations are different. Again, this is quite likeThis does not alter the value of
y.