CommaDelimitedStringCollection Třída
Definice
Důležité
Některé informace platí pro předběžně vydaný produkt, který se může zásadně změnit, než ho výrobce nebo autor vydá. Microsoft neposkytuje žádné záruky, výslovné ani předpokládané, týkající se zde uváděných informací.
Představuje kolekci řetězcových prvků oddělených čárkami. Tato třída se nemůže dědit.
public ref class CommaDelimitedStringCollection sealed : System::Collections::Specialized::StringCollection
public sealed class CommaDelimitedStringCollection : System.Collections.Specialized.StringCollection
type CommaDelimitedStringCollection = class
inherit StringCollection
Public NotInheritable Class CommaDelimitedStringCollection
Inherits StringCollection
- Dědičnost
Příklady
Následující příklad kódu ukazuje, jak použít CommaDelimitedStringCollection typ.
using System;
using System.Collections.Generic;
using System.Text;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Configuration;
using System.Collections.Specialized;
namespace Samples.AspNet.Config
{
class CommaDelimitedStrCollection
{
static void Main(string[] args)
{
// Display title and info.
Console.WriteLine("ASP.NET Configuration Info");
Console.WriteLine("Type: CommaDelimitedStringCollection");
Console.WriteLine();
// Set the path of the config file.
string configPath = "/aspnet";
// Get the Web application configuration object.
Configuration config =
WebConfigurationManager.OpenWebConfiguration(configPath);
// Get the section related object.
AuthorizationSection configSection =
(AuthorizationSection)config.GetSection("system.web/authorization");
// Get the authorization rule collection.
AuthorizationRuleCollection authorizationRuleCollection =
configSection.Rules;
// Create a CommaDelimitedStringCollection object.
CommaDelimitedStringCollection myStrCollection =
new CommaDelimitedStringCollection();
for (int i = 0; i < authorizationRuleCollection.Count; i++)
{
if (authorizationRuleCollection.Get(i).Action.ToString().ToLower()
== "allow")
{
// Add values to the CommaDelimitedStringCollection object.
myStrCollection.AddRange(
authorizationRuleCollection.Get(i).Users.ToString().Split(
",".ToCharArray()));
}
}
Console.WriteLine("Allowed Users: {0}",
myStrCollection.ToString());
// Count the elements in the collection.
Console.WriteLine("Allowed User Count: {0}",
myStrCollection.Count);
// Call the Contains method.
Console.WriteLine("Contains 'userName1': {0}",
myStrCollection.Contains("userName1"));
// Determine the index of an element
// in the collection.
Console.WriteLine("IndexOf 'userName0': {0}",
myStrCollection.IndexOf("userName0"));
// Call IsModified.
Console.WriteLine("IsModified: {0}",
myStrCollection.IsModified);
// Call IsReadyOnly.
Console.WriteLine("IsReadOnly: {0}",
myStrCollection.IsReadOnly);
Console.WriteLine();
Console.WriteLine("Add a user name to the collection.");
// Insert a new element in the collection.
myStrCollection.Insert(myStrCollection.Count, "userNameX");
Console.WriteLine("Collection Value: {0}",
myStrCollection.ToString());
Console.WriteLine();
Console.WriteLine("Remove a user name from the collection.");
// Remove an element of the collection.
myStrCollection.Remove("userNameX");
Console.WriteLine("Collection Value: {0}",
myStrCollection.ToString());
// Display and wait
Console.ReadLine();
}
}
}
Imports System.Collections.Generic
Imports System.Text
Imports System.Configuration
Imports System.Collections
Imports System.Web
Imports System.Web.Configuration
Imports System.Collections.Specialized
Namespace Samples.AspNet.Config
Class CommaDelimitedStrCollection
Shared Sub Main(ByVal args() As String)
' Display title and info.
Console.WriteLine("ASP.NET Configuration Info")
Console.WriteLine("Type: CommaDelimitedStringCollection")
Console.WriteLine()
' Set the path of the config file.
Dim configPath As String = "/aspnet"
' Get the Web application configuration object.
Dim config As Configuration = _
WebConfigurationManager.OpenWebConfiguration(configPath)
' Get the section related object.
Dim configSection As AuthorizationSection = _
CType(config.GetSection("system.web/authorization"), AuthorizationSection)
' Get the authorization rule collection.
Dim authorizationRuleCollection As AuthorizationRuleCollection = _
configSection.Rules()
' Create a CommaDelimitedStringCollection object.
Dim myStrCollection As CommaDelimitedStringCollection = _
New CommaDelimitedStringCollection()
Dim i As Integer
For i = 0 To authorizationRuleCollection.Count - 1 Step i + 1
If authorizationRuleCollection.Get(i).Action.ToString().ToLower() _
= "allow" Then
' Add values to the CommaDelimitedStringCollection object.
myStrCollection.AddRange( _
authorizationRuleCollection.Get(i).Users.ToString().Split( _
",".ToCharArray()))
End If
Next
Console.WriteLine("Allowed Users: {0}", _
myStrCollection.ToString())
' Count the elements in the collection.
Console.WriteLine("Allowed User Count: {0}", _
myStrCollection.Count)
' Call the Contains method.
Console.WriteLine("Contains 'userName1': {0}", _
myStrCollection.Contains("userName1"))
' Determine the index of an element
' in the collection.
Console.WriteLine("IndexOf 'userName0': {0}", _
myStrCollection.IndexOf("userName0"))
' Call IsModified.
Console.WriteLine("IsModified: {0}", _
myStrCollection.IsModified)
' Call IsReadyOnly.
Console.WriteLine("IsReadOnly: {0}", _
myStrCollection.IsReadOnly)
Console.WriteLine()
Console.WriteLine("Add a user name to the collection.")
' Insert a new element in the collection.
myStrCollection.Insert(myStrCollection.Count, "userNameX")
Console.WriteLine("Collection Value: {0}", _
myStrCollection.ToString())
Console.WriteLine()
Console.WriteLine("Remove a user name from the collection.")
' Remove an element of the collection.
myStrCollection.Remove("userNameX")
Console.WriteLine("Collection Value: {0}", _
myStrCollection.ToString())
' Display and wait
Console.ReadLine()
End Sub
End Class
End Namespace
Poznámky
Tato třída představuje kolekci řetězců, která je serializována jako seznam řetězcových prvků oddělených čárkami.
Konstruktory
| Name | Description |
|---|---|
| CommaDelimitedStringCollection() |
Vytvoří novou instanci CommaDelimitedStringCollection třídy. |
Vlastnosti
| Name | Description |
|---|---|
| Count |
Získá počet řetězců obsažených v objektu StringCollection. (Zděděno od StringCollection) |
| IsModified |
Získá hodnotu, která určuje, zda kolekce byla změněna. |
| IsReadOnly |
Získá hodnotu určující, zda objekt kolekce je jen pro čtení. |
| IsSynchronized |
Získá hodnotu označující, zda je přístup k StringCollection této synchronizaci (bezpečné vlákno). (Zděděno od StringCollection) |
| Item[Int32] |
Získá nebo nastaví řetězcový prvek v kolekci na základě indexu. |
| SyncRoot |
Získá objekt, který lze použít k synchronizaci přístupu k StringCollection. (Zděděno od StringCollection) |
Metody
| Name | Description |
|---|---|
| Add(String) |
Přidá řetězec do kolekce s oddělovači. |
| AddRange(String[]) |
Přidá všechny řetězce v řetězcovém poli do kolekce. |
| Clear() |
Vymaže kolekci. |
| Clone() |
Vytvoří kopii kolekce. |
| Contains(String) |
Určuje, zda je zadaný řetězec v sadě StringCollection. (Zděděno od StringCollection) |
| CopyTo(String[], Int32) |
Zkopíruje celé StringCollection hodnoty do jednorozměrného pole řetězců počínaje zadaným indexem cílového pole. (Zděděno od StringCollection) |
| Equals(Object) |
Určuje, zda je zadaný objekt roven aktuálnímu objektu. (Zděděno od Object) |
| GetEnumerator() |
StringEnumerator Vrátí iteruje přes StringCollection. (Zděděno od StringCollection) |
| GetHashCode() |
Slouží jako výchozí funkce hash. (Zděděno od Object) |
| GetType() |
Získá Type aktuální instance. (Zděděno od Object) |
| IndexOf(String) |
Vyhledá zadaný řetězec a vrátí index založený na nule prvního výskytu StringCollectionv rámci . (Zděděno od StringCollection) |
| Insert(Int32, String) |
Přidá prvek řetězce do kolekce v zadaném indexu. |
| MemberwiseClone() |
Vytvoří mělkou kopii aktuálního Object. (Zděděno od Object) |
| Remove(String) |
Odebere z kolekce prvek řetězce. |
| RemoveAt(Int32) |
Odebere řetězec v zadaném indexu objektu StringCollection. (Zděděno od StringCollection) |
| SetReadOnly() |
Nastaví objekt kolekce na jen pro čtení. |
| ToString() |
Vrátí řetězcovou reprezentaci objektu. |
Explicitní implementace rozhraní
| Name | Description |
|---|---|
| ICollection.CopyTo(Array, Int32) |
Zkopíruje celý StringCollection soubor do kompatibilního jednorozměrného Array, počínaje zadaným indexem cílového pole. (Zděděno od StringCollection) |
| IEnumerable.GetEnumerator() |
IEnumerator Vrátí iteruje přes StringCollection. (Zděděno od StringCollection) |
| IList.Add(Object) |
Přidá objekt na konec objektu StringCollection. (Zděděno od StringCollection) |
| IList.Contains(Object) |
Určuje, zda je prvek v objektu StringCollection. (Zděděno od StringCollection) |
| IList.IndexOf(Object) |
Vyhledá zadaný Object index a vrátí index založený na nule prvního výskytu v celém StringCollectionrozsahu . (Zděděno od StringCollection) |
| IList.Insert(Int32, Object) |
Vloží prvek do zadaného indexu StringCollection . (Zděděno od StringCollection) |
| IList.IsFixedSize |
Získá hodnotu určující, zda StringCollection objekt má pevnou velikost. (Zděděno od StringCollection) |
| IList.IsReadOnly |
Získá hodnotu určující, zda StringCollection objekt je jen pro čtení. (Zděděno od StringCollection) |
| IList.Item[Int32] |
Získá nebo nastaví prvek v zadaném indexu. (Zděděno od StringCollection) |
| IList.Remove(Object) |
Odebere první výskyt konkrétního objektu z objektu StringCollection. (Zděděno od StringCollection) |
Metody rozšíření
| Name | Description |
|---|---|
| AsParallel(IEnumerable) |
Umožňuje paralelizaci dotazu. |
| AsQueryable(IEnumerable) |
Převede IEnumerable na IQueryable. |
| Cast<TResult>(IEnumerable) |
Přetypuje prvky IEnumerable na zadaný typ. |
| OfType<TResult>(IEnumerable) |
Filtruje prvky IEnumerable na základě zadaného typu. |