0

I have a class that has several properties, a couple which are string arrays. When the following statement:

MyObj.Str1[1] = "AAA";

MyObj.Str1[1] does not contain "AAA". Using debug breakpoints, I see the set routine doesn't execute (the get routine does execute).

The property looks like:

public string[] Str1
{
    get { return bdr.GetArrVal(1, 25, 7); }
    set { bdr.SetArrVal(1, 25, 7, value); }
}

GetArrVal() builds and returns a string array from class internal data. SetArrVal() sets class internal data from the incoming array.

I tried using indexers but had too many problems passing class internal data into the class describing Str1.

Please note that the statement

MyObj.Str1 = arr1;

works, where arr1 is a string array. The program breaks at the set routine.

All of this makes me think I cant do what I want. Can you assign a single element of a string-array property of an object?

Luiso
  • 4,173
  • 2
  • 37
  • 60

2 Answers2

0

MyObj.Str1 is a string (which is a group of characters) and MyObj.Str1[1] is the char on the second index of that string. You are assigning "AAA" three elements to a single character. This does not make any sense if you are trying to "assign a single element of a string-array property of an object?"

Khalil Khalaf
  • 9,259
  • 11
  • 62
  • 104
0

Str1 is the property name as posted by you public string[] Str1 { which returns a string[]. So when you say MyObj.Str1[1] = "AAA"; you are actually trying to set a array element returned by Str1 property and not the property itself and thus the statement MyObj.Str1 = arr1; works fine.

Rahul
  • 76,197
  • 13
  • 71
  • 125