A property or index cannot be passed as an out or ref parameter, while an Array Resize

While I am trying to resize the array in C # as shown below,

Array.Resize(ref Globals.NameList, 0);

I get the following error

A property or indexer may not be passed as an out or ref parameter

Globals are an object. NameList is an array of string types declared in the Globals class.

Please help me fix this by posting the correct code.

Thank!

+5
source share
3 answers

use a variable but not a property

var obj = Globals.NameList;
Array.Resize(ref obj , 0);
Globals.NameList=obj;
+18
source

The compiler error speaks for itself - you cannot pass a property by reference; only variable.

In the C # 10.6.1.2 specification section:

, ref, ( 5.3.3) , .

-.

, :

var tmp = Globals.NameList;
Array.Reize(ref tmp, 0);
Globals.NameList = tmp;

, VB , . , , .

, Globals - ...

+8

do

Array arr = Globals.NameList;
Array.Resize(ref arr, 0);
Globals.NameList = arr;
0
source

All Articles