ObjectParameterCollection.Count 属性

定义

获取集合中当前存在的参数的数量。

public:
 property int Count { int get(); };
public int Count { get; }
member this.Count : int
Public ReadOnly Property Count As Integer

属性值

集合中当前存在的 ObjectParameter 对象的数量。

实现

示例

此示例将新参数添加到集合,并获取集合中参数的计数。 然后,该示例循环访问 ObjectParameterCollection 并显示集合中每个参数的名称、类型和值。

using (AdventureWorksEntities context =
    new AdventureWorksEntities())
{
    string queryString =
        @"SELECT VALUE contact FROM AdventureWorksEntities.Contacts
        AS contact WHERE contact.LastName = @ln AND contact.FirstName = @fn";

    ObjectQuery<Contact> contactQuery =
        new ObjectQuery<Contact>(queryString, context);

    // Add parameters to the collection.
    contactQuery.Parameters.Add(new ObjectParameter("ln", "Adams"));
    contactQuery.Parameters.Add(new ObjectParameter("fn", "Frances"));

    ObjectParameterCollection objectParameterCollection =
        contactQuery.Parameters;

    Console.WriteLine("Count is {0}.", objectParameterCollection.Count);

    // Iterate through the ObjectParameterCollection collection.
    foreach (ObjectParameter result in objectParameterCollection)
    {
        Console.WriteLine("{0} {1} {2}", result.Name,
            result.Value,
            result.ParameterType);
    }
}

适用于

另请参阅