P
pinetaj
Hello,
I have a question of using 'property' on accessing elements of array.
There is an array member in a class. I'd like to restrict accessing the
elements of the array through property. And also by annotating the set
method of the property with user-defined attribute, i'd like to
activate something whenever the set method is invoked.
I wrote the code as the followings. But, my problem is that it allows
to set a value on an element of the array using property but the set
method is never invoked.
In the following example, PARRINT1 is a property for an array.
I expected that when A1.PARRINT1[1] = 16 is called, the set method of
PARRINT1 is invoked but actually it's not. Actually when A1.PARRINT1 =
new int[4]{21,22,23,24}; is called, the set method is invoked. Is there
any way to make the set method be invoked when the elements of the
array are set?
I checked indexer but that's not what I want.
I appreciate any your advice.
------------
class CTestA
{
priate int[] arrInt1 = new int[4]{11, 12, 13, 14};
public int[] PARRINT1
{
get
{
return arrInt1;
}
[SetAttr]
set
{
arrInt1 = value;
}
}
}//class CTestA
class Test{
static void Main(string[] args)
{
A1 = new CTestA();
A1.PARRINT1[1] = 16;
A1.PARRINT1 = new int[4]{21,22,23,24};
A1.I = 41;
}
} //class Test
I have a question of using 'property' on accessing elements of array.
There is an array member in a class. I'd like to restrict accessing the
elements of the array through property. And also by annotating the set
method of the property with user-defined attribute, i'd like to
activate something whenever the set method is invoked.
I wrote the code as the followings. But, my problem is that it allows
to set a value on an element of the array using property but the set
method is never invoked.
In the following example, PARRINT1 is a property for an array.
I expected that when A1.PARRINT1[1] = 16 is called, the set method of
PARRINT1 is invoked but actually it's not. Actually when A1.PARRINT1 =
new int[4]{21,22,23,24}; is called, the set method is invoked. Is there
any way to make the set method be invoked when the elements of the
array are set?
I checked indexer but that's not what I want.
I appreciate any your advice.
------------
class CTestA
{
priate int[] arrInt1 = new int[4]{11, 12, 13, 14};
public int[] PARRINT1
{
get
{
return arrInt1;
}
[SetAttr]
set
{
arrInt1 = value;
}
}
}//class CTestA
class Test{
static void Main(string[] args)
{
A1 = new CTestA();
A1.PARRINT1[1] = 16;
A1.PARRINT1 = new int[4]{21,22,23,24};
A1.I = 41;
}
} //class Test