asked on
C# non-ref returning property
I am currently updating a 15 year C# project. There are several sections containing code like this.
Array.Resize(ref eConnect.GLAccountType, 1);
eConnect.GLAccountType[0] = GLAccount;
eConnect is reference that contains many methods. On the Array.Resize line I get this message on all occurrences.
"A non ref-returning property or indexer may not be used as an out or ref value"
I have the original project and I get the same messages in there. When I run the code it appears to work if I comment out these lines. I have added the new reference for eConnect with this project.
The code looks OK at first glance but something isn't correct. Can you post how eConnect.GLAccountType is declared/defined.
ASKER
This is in something called eConnectionTpe.decomplied
private GLAccountType[] gLAccountTypeField;
[XmlElement("GLAccountType
public GLAccountType[] GLAccountType
{
get
{
return gLAccountTypeField;
}
set
{
gLAccountTypeField = value;
}
}
eConnect is from a third party ?
dummy dd = new dummy();
int iSizeBefore = dd.iArray.Length;
Array.Resize<int>(ref dd.iArray, 2);
int iSizeAfter = dd.iArray.Length;
iSizeBefore = dd.GLAccountType.Length;
//Array.Resize<int>(ref dd.GLAccountType, 9);
dd.ResizeArray(9);
iSizeAfter = dd.GLAccountType.Length;
int x = 9;
public class dummy
{
public int[] iArray = new int[7];
public int[] GLAccountType
{
get
{
return iArray;
}
set
{
iArray = value;
}
}
public void ResizeArray(int iSize)
{
Array.Resize<int>(ref iArray, iSize);
}
}
Resizing works perfectly when accessing the array directly. I get the same error as you when attempting to use the property. Does the third party code have a function to resize the array (or can you just use the variable in the other class directly rather than via the property?
ASKER
ASKER
ASKER
"Could not find any resources appropriate for the specified culture or the neutral culture"
I copied the cs and designer files from the old project and changed the name space in both. I then added this existing code to this project. Is there something else I could be doing?