private void btnAdd_Click(object sender, System.EventArgs e) { Question q = new Question(); q.Text = this.txtQuestion.Text; for (int i = 0; i < this.txtAnswers.Lines.Length; i++) { if (this.txtAnswers.Lines[i] != "") { string[] line = this.txtAnswers.Lines[i].Split('|'); Answer a = new Answer(line[0], Int32.Parse(line[1])); q.Answers.Add(a); } } this.questions.Add(q); this.listQuestions.Items.Add(q.Text); this.txtAnswers.Clear(); this.txtQuestion.Clear(); this.txtQuestion.Focus(); }
public override void CopyTo(Answer[] array) { m_collection.CopyTo(array); }
public override bool Contains(Answer x) { return m_collection.Contains(x); }
public override void Insert(int pos, Answer x) { rwLock.AcquireWriterLock(timeout); try { collection.Insert(pos,x); } finally { rwLock.ReleaseWriterLock(); } }
public abstract void DisplayAnswer(Answer answer);
public override int IndexOf(Answer x) { int result = 0; rwLock.AcquireReaderLock(timeout); try { result = collection.IndexOf(x); } finally { rwLock.ReleaseReaderLock(); } return result; }
public override bool Contains(Answer x) { bool result = false; rwLock.AcquireReaderLock(timeout); try { result = collection.Contains(x); } finally { rwLock.ReleaseReaderLock(); } return result; }
public override void Remove(Answer x) { throw new NotSupportedException("This is a Read Only Collection and can not be modified"); }
/// <summary> /// Returns the zero-based index of the first occurrence of a <see cref="Answer"/> /// in the <c>AnswerCollection</c>. /// </summary> /// <param name="item">The <see cref="Answer"/> to locate in the <c>AnswerCollection</c>.</param> /// <returns> /// The zero-based index of the first occurrence of <paramref name="item"/> /// in the entire <c>AnswerCollection</c>, if found; otherwise, -1. /// </returns> public virtual int IndexOf(Answer item) { for (int i=0; i != m_count; ++i) if (m_array[i].Equals(item)) return i; return -1; }
/// <summary> /// Copies the entire <c>AnswerCollection</c> to a one-dimensional /// <see cref="Answer"/> array, starting at the specified index of the target array. /// </summary> /// <param name="array">The one-dimensional <see cref="Answer"/> array to copy to.</param> /// <param name="start">The zero-based index in <paramref name="array"/> at which copying begins.</param> public virtual void CopyTo(Answer[] array, int start) { if (m_count > array.GetUpperBound(0) + 1 - start) throw new System.ArgumentException("Destination array was not long enough."); Array.Copy(m_array, 0, array, start, m_count); }
/// <summary> /// Copies the entire <c>AnswerCollection</c> to a one-dimensional /// <see cref="Answer"/> array. /// </summary> /// <param name="array">The one-dimensional <see cref="Answer"/> array to copy to.</param> public virtual void CopyTo(Answer[] array) { this.CopyTo(array, 0); }
/// <summary> /// Determines whether a given <see cref="Answer"/> is in the <c>AnswerCollection</c>. /// </summary> /// <param name="item">The <see cref="Answer"/> to check for.</param> /// <returns><c>true</c> if <paramref name="item"/> is found in the <c>AnswerCollection</c>; otherwise, <c>false</c>.</returns> public virtual bool Contains(Answer item) { for (int i=0; i != m_count; ++i) if (m_array[i].Equals(item)) return true; return false; }
/// <summary> /// Adds the elements of a <see cref="Answer"/> array to the current <c>AnswerCollection</c>. /// </summary> /// <param name="x">The <see cref="Answer"/> array whose elements should be added to the end of the <c>AnswerCollection</c>.</param> /// <returns>The new <see cref="AnswerCollection.Count"/> of the <c>AnswerCollection</c>.</returns> public virtual int AddRange(Answer[] x) { if (m_count + x.Length >= m_array.Length) EnsureCapacity(m_count + x.Length); Array.Copy(x, 0, m_array, m_count, x.Length); m_count += x.Length; m_version++; return m_count; }
/// <summary> /// Adds a <see cref="Answer"/> to the end of the <c>AnswerCollection</c>. /// </summary> /// <param name="item">The <see cref="Answer"/> to be added to the end of the <c>AnswerCollection</c>.</param> /// <returns>The index at which the value has been added.</returns> public virtual int Add(Answer item) { if (m_count == m_array.Length) EnsureCapacity(m_count + 1); m_array[m_count] = item; m_version++; return m_count++; }
public override void Remove(Answer x) { rwLock.AcquireWriterLock(timeout); try { collection.Remove(x); } finally { rwLock.ReleaseWriterLock(); } }
public override void CopyTo(Answer[] array, int start) { m_collection.CopyTo(array,start); }
public override int IndexOf(Answer x) { return m_collection.IndexOf(x); }
/// <summary> /// Inserts an element into the <c>AnswerCollection</c> at the specified index. /// </summary> /// <param name="index">The zero-based index at which <paramref name="item"/> should be inserted.</param> /// <param name="item">The <see cref="Answer"/> to insert.</param> /// <exception cref="ArgumentOutOfRangeException"> /// <para><paramref name="index"/> is less than zero</para> /// <para>-or-</para> /// <para><paramref name="index"/> is equal to or greater than <see cref="AnswerCollection.Count"/>.</para> /// </exception> public virtual void Insert(int index, Answer item) { ValidateIndex(index, true); // throws if (m_count == m_array.Length) EnsureCapacity(m_count + 1); if (index < m_count) { Array.Copy(m_array, index, m_array, index + 1, m_count - index); } m_array[index] = item; m_count++; m_version++; }
public override int AddRange(Answer[] x) { int result = 0; rwLock.AcquireWriterLock(timeout); try { result = collection.AddRange(x); } finally { rwLock.ReleaseWriterLock(); } return result; }
/// <summary> /// Removes the first occurrence of a specific <see cref="Answer"/> from the <c>AnswerCollection</c>. /// </summary> /// <param name="item">The <see cref="Answer"/> to remove from the <c>AnswerCollection</c>.</param> /// <exception cref="ArgumentException"> /// The specified <see cref="Answer"/> was not found in the <c>AnswerCollection</c>. /// </exception> public virtual void Remove(Answer item) { int i = IndexOf(item); if (i < 0) throw new System.ArgumentException("Cannot remove the specified item because it was not found in the specified Collection."); ++m_version; RemoveAt(i); }
public override void CopyTo(Answer[] array, int start) { rwLock.AcquireReaderLock(timeout); try { collection.CopyTo(array, start); } finally { rwLock.ReleaseReaderLock(); } }
/// <summary> /// Removes the element at the specified index of the <c>AnswerCollection</c>. /// </summary> /// <param name="index">The zero-based index of the element to remove.</param> /// <exception cref="ArgumentOutOfRangeException"> /// <para><paramref name="index"/> is less than zero</para> /// <para>-or-</para> /// <para><paramref name="index"/> is equal to or greater than <see cref="AnswerCollection.Count"/>.</para> /// </exception> public virtual void RemoveAt(int index) { ValidateIndex(index); // throws m_count--; if (index < m_count) { Array.Copy(m_array, index + 1, m_array, index, m_count - index); } // We can't set the deleted entry equal to null, because it might be a value type. // Instead, we'll create an empty single-element array of the right type and copy it // over the entry we want to erase. Answer[] temp = new Answer[1]; Array.Copy(temp, 0, m_array, m_count, 1); m_version++; }
public override void DisplayAnswer(Answer answer) { this.state = GameState.Display; this.output = answer.Text + " (" + answer.Votes + ")"; }
/// <summary> /// Initializes a new instance of the <c>AnswerCollection</c> class /// that contains elements copied from the specified <see cref="Answer"/> array. /// </summary> /// <param name="a">The <see cref="Answer"/> array whose elements are copied to the new list.</param> public AnswerCollection(Answer[] a) { m_array = new Answer[a.Length]; AddRange(a); }
public override int AddRange(Answer[] x) { throw new NotSupportedException("This is a Read Only Collection and can not be modified"); }
public override void DisplayAnswer(Answer answer) { this.controlForm.AddAnswer(answer.Text); this.gameDisplay.AddAnswer(answer.Text, answer.Votes); }