SelectedDatesCollection.CopyTo Method
Copies the items from the SelectedDatesCollection to the specified System.Array, starting with the specified index.
[Visual Basic] Public Overridable Sub CopyTo( _ ByVal array As Array, _ ByVal index As Integer _ ) Implements ICollection.CopyTo [C#] public virtual void CopyTo( Array array, int index ); [C++] public: virtual void CopyTo( Array* array, int index ); [JScript] public function CopyTo( array : Array, index : int );
Parameters
- array
- A zero-based System.Array that receives the copied items from the SelectedDatesCollection.
- index
- The first index in the specified System.Array to receive the items.
Implements
Remarks
Use this method to copy the contents of the SelectedDatesCollection into the specified System.Array, starting at the specified index.
Note The array parameter must be a zero-based System.Array.
Example
[Visual Basic, C#] The following example demonstrates how to use the CopyTo method to copy items from the SelectedDatesCollection into the specified array.
[Visual Basic] <%@ Page Language="VB" AutoEventWireup="True" %> <html> <head> <script runat="server"> Sub Select_Change(sender As Object, e As EventArgs) Dim myDateArray(Calendar1.SelectedDates.Count) As DateTime ' Copy the collection to array. Calendar1.SelectedDates.CopyTo(myDateArray, 0) Label1.Text = "The dates selected are: " ' Loop through the IEnumerator and display the contents. Dim theDate As DateTime For Each theDate In myDateArray Label1.Text &= " " & theDate.Day.ToString() Next End Sub </script> </head> <body> <form runat="server"> <asp:Calendar ID="Calendar1" runat="server" SelectionMode="DayWeekMonth" OnSelectionChanged="Select_Change"/> <hr> Select dates from the Calendar.<br><br> <asp:Label id="Label1" runat=server /> </form> </body> </html> [C#] <%@ Page Language="C#" AutoEventWireup="True" %> <html> <head> <script runat="server"> void Select_Change(Object sender, EventArgs e) { DateTime[] myDateArray = new DateTime[Calendar1.SelectedDates.Count]; // Copy the collection to an array. Calendar1.SelectedDates.CopyTo(myDateArray, 0); Label1.Text = "The dates selected are: "; // Loop through the IEnumerator and display the contents. foreach (DateTime date in myDateArray) { Label1.Text += " " + date.Day.ToString(); } } </script> </head> <body> <form runat="server"> <asp:Calendar ID="Calendar1" runat="server" SelectionMode="DayWeekMonth" OnSelectionChanged="Select_Change"/> <hr> Select dates from the Calendar.<br><br> <asp:Label id="Label1" runat=server /> </form> </body> </html>
[C++, JScript] No example is available for C++ or JScript. To view a Visual Basic or C# example, click the Language Filter button
in the upper-left corner of the page.
Requirements
Platforms: Windows 2000, Windows XP Professional, Windows Server 2003 family
See Also
SelectedDatesCollection Class | SelectedDatesCollection Members | System.Web.UI.WebControls Namespace | System.Array