DiscoveryReferenceCollection.Item[Int32] 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取或设置指定索引处的 DiscoveryReference。
public:
property System::Web::Services::Discovery::DiscoveryReference ^ default[int] { System::Web::Services::Discovery::DiscoveryReference ^ get(int i); void set(int i, System::Web::Services::Discovery::DiscoveryReference ^ value); };
public System.Web.Services.Discovery.DiscoveryReference this[int i] { get; set; }
member this.Item(int) : System.Web.Services.Discovery.DiscoveryReference with get, set
Default Public Property Item(i As Integer) As DiscoveryReference
参数
- i
- Int32
要获取或设置的 DiscoveryReference 的从零开始的索引。
属性值
指定索引处的 DiscoveryReference。
例外
i
不是 DiscoveryReferenceCollection 中的有效索引。
示例
int main()
{
DiscoveryDocumentReference^ myDiscoveryDocReference1 = gcnew DiscoveryDocumentReference;
DiscoveryDocumentReference^ myDiscoveryDocReference2 = gcnew DiscoveryDocumentReference;
DiscoveryReference^ myDiscoveryReference;
Console::WriteLine( "Demonstrating DiscoveryReferenceCollection class." );
// Create new DiscoveryReferenceCollection.
DiscoveryReferenceCollection^ myDiscoveryReferenceCollection = gcnew DiscoveryReferenceCollection;
// Access the Count method.
Console::WriteLine( "The number of elements in the collection is: {0}", myDiscoveryReferenceCollection->Count );
// Add elements to the collection.
myDiscoveryReferenceCollection->Add( myDiscoveryDocReference1 );
myDiscoveryReferenceCollection->Add( myDiscoveryDocReference2 );
Console::WriteLine( "The number of elements in the collection after adding two elements to the collection: {0}", myDiscoveryReferenceCollection->Count );
// Call the Contains method.
if ( myDiscoveryReferenceCollection->Contains( myDiscoveryDocReference1 ) != true )
{
throw gcnew Exception( "Element not found in collection." );
}
// Access the indexed member.
myDiscoveryReference = dynamic_cast<DiscoveryReference^>(myDiscoveryReferenceCollection[ 0 ]);
if ( myDiscoveryReference == nullptr )
{
throw gcnew Exception( "Element not found in collection." );
}
// Remove one element from collection.
myDiscoveryReferenceCollection->Remove( myDiscoveryDocReference1 );
Console::WriteLine( "The number of elements in the collection after removing one element is: {0}", myDiscoveryReferenceCollection->Count );
}
class MyDiscoveryDocumentClass
{
static void Main()
{
DiscoveryDocumentReference myDiscoveryDocReference1 =
new DiscoveryDocumentReference();
DiscoveryDocumentReference myDiscoveryDocReference2 =
new DiscoveryDocumentReference();
DiscoveryReference myDiscoveryReference;
Console.WriteLine("Demonstrating DiscoveryReferenceCollection class.");
// Create new DiscoveryReferenceCollection.
DiscoveryReferenceCollection myDiscoveryReferenceCollection =
new DiscoveryReferenceCollection();
// Access the Count method.
Console.WriteLine("The number of elements in the collection is: "
+ myDiscoveryReferenceCollection.Count.ToString());
// Add elements to the collection.
myDiscoveryReferenceCollection.Add(myDiscoveryDocReference1);
myDiscoveryReferenceCollection.Add(myDiscoveryDocReference2);
Console.WriteLine("The number of elements in the collection "
+ "after adding two elements to the collection: "
+ myDiscoveryReferenceCollection.Count.ToString());
// Call the Contains method.
if (myDiscoveryReferenceCollection.Contains(myDiscoveryDocReference1)
!= true)
{
throw new Exception("Element not found in collection.");
}
// Access the indexed member.
myDiscoveryReference =
(DiscoveryReference)myDiscoveryReferenceCollection[0];
if (myDiscoveryReference == null)
{
throw new Exception("Element not found in collection.");
}
// Remove one element from collection.
myDiscoveryReferenceCollection.Remove(myDiscoveryDocReference1);
Console.WriteLine("The number of elements in the collection "
+ "after removing one element is: "
+ myDiscoveryReferenceCollection.Count.ToString());
}
Class MyDiscoveryDocumentMod
Shared Sub Main()
Try
Dim myDiscoveryDocReference1 As New DiscoveryDocumentReference()
Dim myDiscoveryDocReference2 As New DiscoveryDocumentReference()
Dim myDiscoveryReference As DiscoveryReference
Console.WriteLine("Demonstrating DiscoveryReferenceCollection class.")
' Create new DiscoveryReferenceCollection.
Dim myDiscoveryReferenceCollection As New DiscoveryReferenceCollection()
' Access the Count method.
Console.WriteLine("The number of elements in collection is: " & _
myDiscoveryReferenceCollection.Count.ToString())
' Add elements to the collection.
myDiscoveryReferenceCollection.Add(myDiscoveryDocReference1)
myDiscoveryReferenceCollection.Add(myDiscoveryDocReference2)
Console.WriteLine("The number of elements in the collection " _
& "after adding two elements to the collection: " _
& myDiscoveryReferenceCollection.Count.ToString())
' Call the Contains method.
If myDiscoveryReferenceCollection.Contains(myDiscoveryDocReference1) _
<> True Then
Throw New Exception("Element not found in collection.")
End If
' Access the Item property.
myDiscoveryReference = myDiscoveryReferenceCollection.Item(0)
If myDiscoveryReference Is Nothing Then
Throw New Exception("Element not found in collection.")
End If
' Remove one element from the collection.
myDiscoveryReferenceCollection.Remove(myDiscoveryDocReference1)
Console.WriteLine("The number of elements in collection " _
& "after removing one element is: " _
& myDiscoveryReferenceCollection.Count.ToString())
Catch e As Exception
Console.Writeline("Exception occurred : " + e.Message)
End Try
End Sub
End Class