我正在尝试使用索引器来解决类中的数组属性。请让我知道如何根据以下代码示例进行处理。基于索引的属性应该能够在内部更新另一个属性。
遗留结构:
Record LegacyRec type basicRecord
3 TOTALPAID num(13,2) ;
3 TABLEOC2 char(85) ; // ONE OCCUR OF DATA - Below items are part of TABELOC2
4 DUEDATEX char(10) ;
4 ACCTX char(6) ;
4 TAXX num(9,2) ;
4 PENALTYX num(9,2) ;
4 INTERESTX num(9,2) ;
4 FEESX num(9,2) ;
4 TOTALPAIDX num(13,2) ;
4 SEQNUMX smallint ;
4 BILLNUMX char(8) ;
4 FILEDDATEX char(10) ;
3 TABLEKEY char(12) ; // TABLEKEY
4 TABLEID char(8) ;
4 TABLECODE char(4) ;
3 TABLEALL char(29750) ; // UP TO 400 OCCURS
4 TABLEOC1 char(85) [350] ; // INDEXED REDEFINE OF ABOVE
3 TABLESCREEN char(1275) ; // UP TO 15 OCCURS - It holds the data below array
4 TABLESCR char(61) [15] ; // INDEXED REDEFINE OF ABOVE
5 DUEDATES char(10) ;
5 ACCTS char(6) ;
5 TAXS num(9,2) ;
5 SEQNUMS smallint ;
5 CNT int ;
5 BILLNUMS char(10) ;
5 FILEDDATES char(20) ;
end
前端代码:(无法更改,但我可以在需要时调用一些附加函数)
decimal x;
string y;
LegacyRec XYZ1 = new LegacyRec();
XYZ1.TABLEOC2 = "ABCDEFGHIJXYZPQR 1234.78 67 4567.89 755553.55 56 63744.6 1RTY ZXCVBNMIOP";
x = XYZ1.PENALTYX;
y = XYZ1.DUEDATEX;
y = XYZ1.FILEDDATEX;
XYZ1.PENALTYX = 111.11M;
XYZ1.SEQNUMX = 34;
XYZ1.FILEDDATEX = "1234567890";
XYZ1.TABLEOC1[2]= "RRRR";
XYZ1.bdate = 10;
XYZ1.iitem[1] = 123;
XYZ1.il6[2] = "RTRRRTY";
for (int i = 1; i < XYZ1.TABLESCR.Count(); i++)
XYZ1.TABLESCR[i] = "";
XYZ1.TABLESCR[6] = "10/10/2010A5670056.89 231000AAA 20200202";
y = XYZ1.TAXS[6] ; //should show 56.89
.NET 类 //我当前的结构缺少索引器。我在使用 Indexer 设置数组属性数组时遇到问题。
public class LegacyRec: basicRecord
{
public decimal TOTALPAID { get; set; }
public string TABLEOC2 { get; set; } //Main field
public string DUEDATEX {
get { return getPartialData(TABLEOC2, 1, 10).ToString(); }
set { TABLEOC2 = setPartialData(TABLEOC2, 1, 10, value).ToString(); } } //Sub Fields
public string ACCTX {
get { return getPartialData(TABLEOC2, 11, 6).ToString(); }
set { TABLEOC2 = setPartialData(TABLEOC2, 11, 6, value).ToString(); } } //Sub Fields
public decimal TAXX {
get { try { return decimal.Parse(getPartialData(TABLEOC2, 17, 9).ToString()); } catch { return 0; } }
set { TABLEOC2 = setPartialData(TABLEOC2, 11, 6, value).ToString(); } } //Sub Fields
public decimal PENALTYX {
get { try { return decimal.Parse(getPartialData(TABLEOC2, 26, 9).ToString()); } catch { return 0; } }
set { TABLEOC2 = setPartialData(TABLEOC2, 26, 9, value).ToString(); } } //Sub Fields
public decimal INTERESTX {
get { try { return decimal.Parse(getPartialData(TABLEOC2, 35, 9).ToString()); } catch { return 0; } }
set { TABLEOC2 = setPartialData(TABLEOC2, 35, 9, value).ToString(); } } //Sub Fields
public decimal FEESX {
get { try { return decimal.Parse(getPartialData(TABLEOC2, 44, 9).ToString()); } catch { return 0; } }
set { TABLEOC2 = setPartialData(TABLEOC2, 44, 9, value).ToString(); } } //Sub Fields
public decimal TOTALPAIDX {
get { try { return decimal.Parse(getPartialData(TABLEOC2, 53, 13).ToString()); } catch { return 0; } }
set { TABLEOC2 = setPartialData(TABLEOC2, 53, 13, value).ToString(); } } //Sub Fields
public int SEQNUMX {
get { try { return int.Parse(getPartialData(TABLEOC2, 66, 2).ToString()); } catch { return 0; } }
set { TABLEOC2 = setPartialData(TABLEOC2, 66, 2, value).ToString(); } } //Sub Fields
public string BILLNUMX {
get { return getPartialData(TABLEOC2, 68, 8).ToString(); }
set { TABLEOC2 = setPartialData(TABLEOC2, 68, 8, value).ToString(); } } //Sub Fields
public string FILEDDATEX {
get { return getPartialData(TABLEOC2, 76, 10).ToString(); }
set { TABLEOC2 = setPartialData(TABLEOC2, 76, 10, value).ToString(); } } //Sub Fields
public string TABLEALL { get; set; } // UP TO 400 OCCURS
private string[] _TABLEOC1;
public string this[int index] //not working
{
get { return _TABLEOC1[index]; }
set { _TABLEOC1[index] = value; TABLEALL = setPartialData(_TABLEOC1[index], index*10, 10, value).ToString(); //not working at this time}
}
public string[] TABLEOC1 {
get { return _TABLEOC1; }
set { TABLEALL = setPartialData(TABLEOC1[index], index*, 85, value).ToString(); } } // INDEXED REDEFINE OF ABOVE [350]
private string[] _TABLESCR;
public string[] TABLESCR { get { return _TABLESCR; } set { string s = "123"; } } //Main array with TableScreen
public string[] DUEDATES {
get from TABLESCR[index];
set TABLESCR particular Index; }
public string[] ACCTS {
get from TABLESCR[index];
set TABLESCR particular Index; }
public decimal[] TAXS {
get from TABLESCR[index];
set TABLESCR particular Index;}
public int[] SEQNUMS {
get from TABLESCR[index];
set TABLESCR particular Index;}
public int[] CNT {
get from TABLESCR[index];
set TABLESCR particular Index;}
public string[] BILLNUMS {
get from TABLESCR[index];
set TABLESCR particular Index;}
public string[] FILEDDATES {
get from TABLESCR[index];
set TABLESCR particular Index;}
}