SelectedDatesCollection.GetEnumerator Metodo
Definizione
Importante
Alcune informazioni sono relative alla release non definitiva del prodotto, che potrebbe subire modifiche significative prima della release definitiva. Microsoft non riconosce alcuna garanzia, espressa o implicita, in merito alle informazioni qui fornite.
Restituisce un IEnumeratoroggetto implementato da che contiene tutti gli DateTime oggetti all'interno dell'insieme SelectedDatesCollection .
public:
virtual System::Collections::IEnumerator ^ GetEnumerator();
public System.Collections.IEnumerator GetEnumerator();
abstract member GetEnumerator : unit -> System.Collections.IEnumerator
override this.GetEnumerator : unit -> System.Collections.IEnumerator
Public Function GetEnumerator () As IEnumerator
Restituisce
Oggetto IEnumeratorimplementato da che contiene tutti gli DateTime oggetti all'interno di SelectedDatesCollection.
Implementazioni
Esempio
Nell'esempio di codice seguente viene illustrato come utilizzare il GetEnumerator metodo per creare un System.Collections.IEnumeratoroggetto implementato da per visualizzare le date selezionate dal Calendar controllo .
<%@ Page Language="C#" AutoEventWireup="True" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>ASP.NET Example</title>
<script runat="server">
void Select_Change(Object sender, EventArgs e)
{
DateTime current_date;
// Create IEnumerator.
IEnumerator myEnum = Calendar1.SelectedDates.GetEnumerator();
Label1.Text = "The dates selected are: ";
// Loop through the IEnumerator and display the contents.
while (myEnum.MoveNext())
{
current_date = (DateTime)myEnum.Current;
Label1.Text += " " + current_date.Day.ToString();
}
}
</script>
</head>
<body>
<form id="form1" 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>
<%@ Page Language="VB" AutoEventWireup="True" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>ASP.NET Example</title>
<script runat="server">
Sub Select_Change(sender As Object, e As EventArgs)
Dim current_date As DateTime
' Create IEnumerator.
Dim myEnum As IEnumerator = Calendar1.SelectedDates.GetEnumerator()
Label1.Text = "The dates selected are: "
' Loop through the IEnumerator and display the contents.
While myEnum.MoveNext()
current_date = CType(myEnum.Current, DateTime)
Label1.Text &= " " & current_date.Day.ToString()
End While
End Sub
</script>
</head>
<body>
<form id="form1" 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>
Commenti
Utilizzare questo metodo per creare un System.Collections.IEnumeratoroggetto implementato da che può essere facilmente iterato per ottenere ogni elemento nella SelectedDatesCollection raccolta.
Utilizzare la IEnumerator.Current proprietà per ottenere l'elemento a cui punta attualmente nell'insieme.
Utilizzare il IEnumerator.MoveNext metodo per passare all'elemento successivo dell'insieme.
Utilizzare il IEnumerator.Reset metodo per spostare nuovamente l'enumeratore nella posizione iniziale.
Annotazioni
Il IEnumerator.MoveNext metodo deve essere chiamato dopo la creazione di un System.Collections.IEnumeratoroggetto implementato da o l'utilizzo del IEnumerator.Reset metodo per spostare l'enumeratore nel primo elemento dell'insieme. In caso contrario, l'elemento rappresentato dalla IEnumerator.Current proprietà non è definito.