25.07.2017 Views

Intro-CSharp-Book-v2015

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Глава 16. Линейни структури от данни 651<br />

}<br />

}<br />

return arr[index];<br />

}<br />

set<br />

{<br />

if (index >= count || index < 0)<br />

{<br />

throw new ArgumentOutOfRangeException(<br />

"Invalid index: " + index);<br />

}<br />

arr[index] = value;<br />

}<br />

Добавяме и операции за изтриване на елементи:<br />

/// <br />

/// Removes the element at the specified index<br />

/// <br />

/// <br />

/// The index, whose element you want to remove<br />

/// <br />

/// The removed element<br />

public object RemoveAt(int index)<br />

{<br />

if (index >= count || index < 0)<br />

{<br />

throw new ArgumentOutOfRangeException("Invalid index: " +<br />

index);<br />

}<br />

object item = arr[index];<br />

Array.Copy(arr, index + 1, arr, index, count - index + 1);<br />

arr[count - 1] = null;<br />

count--;<br />

}<br />

return item;<br />

/// <br />

/// Removes the specified item<br />

/// <br />

/// The item you want to remove<br />

/// Item index or -1 if item does not exists<br />

public int Remove(object item)<br />

{<br />

int index = IndexOf(item);<br />

if (index == -1)

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!