本文整理汇总了C#中System.Configuration.CommaDelimitedStringCollection类的典型用法代码示例。如果您正苦于以下问题:C# CommaDelimitedStringCollection类的具体用法?C# CommaDelimitedStringCollection怎么用?C# CommaDelimitedStringCollection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CommaDelimitedStringCollection类属于System.Configuration命名空间,在下文中一共展示了CommaDelimitedStringCollection类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: Main
//引入命名空间
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();
}
}
}
开发者ID:.NET开发者,项目名称:System.Configuration,代码行数:97,代码来源:CommaDelimitedStringCollection
注:本文中的System.Configuration.CommaDelimitedStringCollection类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论