哦这样能够理解,不过,。。不好意思,这个问题和另一个问题是并发的,所以我昏头了 在同一个类中(我这个类是用来当webservice的)有这么个函数,调用的时候就出现instan access错误,不管我写了new element[i]或者没写都一样 [ WebMethod ( Description = "get all registered inc. informations from database, the result is a array of IncInformation class, the returned int value identify the number of records recrieved " ) ] public int GetAllIncInformation ( out IncInformation[] _iI ) { string [] incID ; int t = GetAllIncID( out incID ); _iI = new IncInformation [t]; for ( int i = 0; i <= t -1; i++) { _iI[i] = new IncInformation();//这里不管写了还是没写都错误啊 GetIncInformation ( incID[i], out _iI[i] ); } return t; }
_iI[i] = new IncInformation();//这里是肯定不用写这句话的了,如果你的GetIncInformation能够编译通过的话。 }GetIncInformation如果没有没有new _iI[i],带out就编译不过了
我完全明白清楚了,但是问题我还是找不出在哪里? 我把这两个函数都写出来吧: public int GetAllIncInformation ( out IncInformation[] _iI ) { string [] incID ; int t = GetAllIncID( out incID ); _iI = new IncInformation [t]; for ( int i = 0; i <= t -1; i++) { GetIncInformation ( incID[i], out _iI[i] ); } return t; } public bool GetIncInformation ( string _incID, out IncInformation _ii ) { if ( ! ExistIncID( _incID ) ) { _ii = new IncInformation(); return false; }; string commaStr = "select addInfo, email, incAtt, incHomepage, incLoc, incName, ID, phone, PW from incInformation where ID = " + "'" + _incID + "'"; myCommand.CommandText = commaStr; SqlDataReader myReader = myCommand.ExecuteReader(); IncInformation ii = new IncInformation(); myReader.Read() ; if ( ! myReader.IsDBNull(0) ) ii.addInfo = myReader.GetString(0); if ( ! myReader.IsDBNull(1) ) ii.email = myReader.GetString(1); if ( ! myReader.IsDBNull(2) ) ii.incAtt = myReader.GetString(2); if ( ! myReader.IsDBNull(3) ) ii.incHomepage = myReader.GetString(3); if ( ! myReader.IsDBNull(4) ) ii.incLoc = myReader.GetString(4); if ( ! myReader.IsDBNull(5) ) ii.incName = myReader.GetString(5); if ( ! myReader.IsDBNull(6) ) ii.ID = myReader.GetString(6); if ( ! myReader.IsDBNull(7) ) ii.phone = myReader.GetString(7); if ( ! myReader.IsDBNull(8) ) ii.PW = myReader.GetString(8); myReader.Close(); _ii = ii; return true; }
两种return你都new了 _ii = new IncInformation(); return false;IncInformation ii = new IncInformation(); 。。 _ii = ii; return true;
(MatchedJob)myEnumer.Current已经返回一个instance了
在同一个类中(我这个类是用来当webservice的)有这么个函数,调用的时候就出现instan access错误,不管我写了new element[i]或者没写都一样 [ WebMethod ( Description = "get all registered inc. informations from database, the result is a array of IncInformation class, the returned int value identify the number of records recrieved " ) ]
public int GetAllIncInformation ( out IncInformation[] _iI )
{
string [] incID ;
int t = GetAllIncID( out incID );
_iI = new IncInformation [t];
for ( int i = 0; i <= t -1; i++)
{
_iI[i] = new IncInformation();//这里不管写了还是没写都错误啊
GetIncInformation ( incID[i], out _iI[i] );
}
return t;
}
我把这两个函数都写出来吧:
public int GetAllIncInformation ( out IncInformation[] _iI )
{
string [] incID ;
int t = GetAllIncID( out incID );
_iI = new IncInformation [t];
for ( int i = 0; i <= t -1; i++)
{
GetIncInformation ( incID[i], out _iI[i] );
}
return t;
} public bool GetIncInformation ( string _incID, out IncInformation _ii )
{
if ( ! ExistIncID( _incID ) )
{
_ii = new IncInformation();
return false;
};
string commaStr = "select addInfo, email, incAtt, incHomepage, incLoc, incName, ID, phone, PW from incInformation where ID = " + "'" + _incID + "'";
myCommand.CommandText = commaStr;
SqlDataReader myReader = myCommand.ExecuteReader();
IncInformation ii = new IncInformation();
myReader.Read() ; if ( ! myReader.IsDBNull(0) )
ii.addInfo = myReader.GetString(0);
if ( ! myReader.IsDBNull(1) )
ii.email = myReader.GetString(1);
if ( ! myReader.IsDBNull(2) )
ii.incAtt = myReader.GetString(2);
if ( ! myReader.IsDBNull(3) )
ii.incHomepage = myReader.GetString(3);
if ( ! myReader.IsDBNull(4) )
ii.incLoc = myReader.GetString(4);
if ( ! myReader.IsDBNull(5) )
ii.incName = myReader.GetString(5);
if ( ! myReader.IsDBNull(6) )
ii.ID = myReader.GetString(6);
if ( ! myReader.IsDBNull(7) )
ii.phone = myReader.GetString(7);
if ( ! myReader.IsDBNull(8) )
ii.PW = myReader.GetString(8); myReader.Close();
_ii = ii;
return true;
}
_ii = new IncInformation();
return false;IncInformation ii = new IncInformation();
。。
_ii = ii;
return true;