Here is my code:
private bool GenericSummaryResultComparison
{
try
{
T oRiskRecord;
//Read in the result files.
oRiskRecord = SerializationMethods.DeserializeIt
foreach (T o in oRiskRecord)
{
// actions
}
return true;
}
catch (Exception ex)
{
throw new ArgumentException(ex.Message, ex.InnerException);
}
}
How can I get this iteration to work?
Thanks

Jaganathan BantheswaranRank #170 · 14.1K reputationPosted Jun 8, 2011, 2:02 AM EDT
Instead of T use "var".
Praneeth KumarRank #4,422 · 344 reputationPosted Jun 8, 2011, 2:15 AM EDT
{
// actions
}
In this line it throws error because oRiskRecord is not of type collection which is implementing IEnumerator. Can you post any sample project if you have?
Regards,
Praneeth
Mark Maguire17 reputationPosted Jun 8, 2011, 2:28 AM EDT
I accidently submitted this one before i completed it.
Let me know if that helps you in anyway.
The code below is from the class object representing RiskRecord, it shows that I have incorporated IEnumerable and IEnumerator (NOTE: I have removed data properties from the RiskRecord class as it would be too long to include them).
public class RiskRecord : ISerializable, IEnumerable { #region Private IEnumerable declarations public RiskRecord[] oRiskRecordElements; #endregionpublic class RiskRecordEnumerator : IEnumerator { private int iPos = -1; private RiskRecord oRiskRecord; public RiskRecordEnumerator(RiskRecord oRiskRecord) { try { this.oRiskRecord = oRiskRecord; } catch (Exception ex) { throw new ArgumentException(ex.Message, ex.InnerException); } } //Declare the MoveNext method as required by the IEnumerator. public bool MoveNext() { try { if (iPos return true; } else { return false; } } catch (Exception ex) { throw new ArgumentException(ex.Message, ex.InnerException); } } //Declare the Reset method required by the IEnumerator public void Reset() { iPos = -1; } //Declare the Current property required by the IEnumerator public object Current { get { return oRiskRecord.oRiskRecordElements[iPos]; } } }Thanks
Mark
Praneeth KumarRank #4,422 · 344 reputationPosted Jun 8, 2011, 2:41 AM EDT
Try this public class RiskRecord : ISerializable, IEnumerable { #region Private IEnumerable declarations public RiskRecord[] oRiskRecordElements; #endregionpublic RiskRecord(RiskRecord[] oArray) { //No contructor code required. //NOTE: This contructor is required for serialization. oRiskRecordElements = oArray; } #region IEnumerable Members public IEnumerator GetEnumerator() { return (IEnumerator)new RiskRecordEnumerator(this); } #endregionpublic class RiskRecordEnumerator : IEnumerator { private int iPos = -1; private RiskRecord oRiskRecord; public RiskRecordEnumerator(RiskRecord oRiskRecord) { try { this.oRiskRecord = oRiskRecord; } catch (Exception ex) { throw new ArgumentException(ex.Message, ex.InnerException); } } //Declare the MoveNext method as required by the IEnumerator. public bool MoveNext() { try { if (iPos return true; } else { return false; } } catch (Exception ex) { throw new ArgumentException(ex.Message, ex.InnerException); } } //Declare the Reset method required by the IEnumerator public void Reset() { iPos = -1; } //Declare the Current property required by the IEnumerator public object Current { get { return oRiskRecord.oRiskRecordElements[iPos]; } } }Mark Maguire17 reputationPosted Jun 8, 2011, 2:43 AM EDT
It still has the problem even with the GetEnumerator code in it.
Thanks
Mark
Praneeth KumarRank #4,422 · 344 reputationPosted Jun 8, 2011, 2:54 AM EDT
oRiskRecord = SerializationMethods.DeserializeIt