Question 4


Exam Question

Drag and Drop

You are developing a custom collecton named LoanCollecton for a class named Loan class. You need to ensure that you can process each Loan object in the LoanCollecton collecton by using a foreach loop. How should you complete the relevant code? (To answer, drag the appropriate code segments to the correct locatons in the answer are
a. Each code segment may be used once, more than once, or not at all. You may need to drag the split bar between panes or scroll to view content.)

  • : IComparable
  • : IEnumerable
  • : IDisposable
  • public IEnumerator GetEnumerator()
  • public int CompareTo(object obj)
  • public void Dispose()
  • _loadCollection[0].Amount++;
  • return obj == null? 1 : _loanCollection.Length;
  • return _loanCollection.GetEnumerator();
public class LoanCollection
    {
    private readonly Load[] _loanCollection;
    public LoanCollection(Loan[] loanArray)
    {
    _loanCollection = new Loan(loanArray.Length);
    for (int i = 0; i < loanArray.Length; i++)
    {
    _loanCollection[i] = loanArray[i];
    }
    }
      {
        }
        }

        Answer:

        • : IComparable
        • : IDisposable
        • public int CompareTo(object obj)
        • public void Dispose()
        • _loadCollection[0].Amount++;
        • return obj == null? 1 : _loanCollection.Length;
        public class LoanCollection
        • : IEnumerable
        {
        private readonly Load[] _loanCollection;
        public LoanCollection(Loan[] loanArray)
        {
        _loanCollection = new Loan(loanArray.Length);
        for (int i = 0; i < loanArray.Length; i++)
        {
        _loanCollection[i] = loanArray[i];
        }
        }
        • public IEnumerator GetEnumerator()
        {
        • return _loanCollection.GetEnumerator();
        }
        }