ConnectionStringSettingsCollection 类
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
包含 ConnectionStringSettings 对象的集合。
public ref class ConnectionStringSettingsCollection sealed : System::Configuration::ConfigurationElementCollection
[System.Configuration.ConfigurationCollection(typeof(System.Configuration.ConnectionStringSettings))]
public sealed class ConnectionStringSettingsCollection : System.Configuration.ConfigurationElementCollection
[<System.Configuration.ConfigurationCollection(typeof(System.Configuration.ConnectionStringSettings))>]
type ConnectionStringSettingsCollection = class
inherit ConfigurationElementCollection
Public NotInheritable Class ConnectionStringSettingsCollection
Inherits ConfigurationElementCollection
- 继承
- 属性
示例
以下示例演示如何访问 ConnectionStringSettingsCollection。
static void ShowConnectionStrings()
{
// Get the application configuration file.
System.Configuration.Configuration config =
ConfigurationManager.OpenExeConfiguration(
ConfigurationUserLevel.None);
// Get the connectionStrings section.
ConnectionStringsSection csSection =
config.ConnectionStrings;
for (int i = 0; i <
ConfigurationManager.ConnectionStrings.Count; i++)
{
ConnectionStringSettings cs =
csSection.ConnectionStrings[i];
Console.WriteLine($" Connection String: \"{cs.ConnectionString}\"");
Console.WriteLine($"#{i}");
Console.WriteLine($" Name: {cs.Name}");
Console.WriteLine($" Provider Name: {cs.ProviderName}");
}
}
Shared Sub ShowConnectionStrings()
' Get the application configuration file.
Dim config _
As System.Configuration.Configuration = _
ConfigurationManager.OpenExeConfiguration( _
ConfigurationUserLevel.None)
' Get the conectionStrings section.
Dim csSection _
As ConnectionStringsSection = _
config.ConnectionStrings
For i As Integer = 0 To ConfigurationManager.ConnectionStrings.Count - 1
Dim cs As ConnectionStringSettings = _
csSection.ConnectionStrings(i)
Console.WriteLine( _
" Connection String: ""{0}""", cs.ConnectionString)
Console.WriteLine("#{0}", i)
Console.WriteLine(" Name: {0}", cs.Name)
Console.WriteLine( _
" Provider Name: {0}", cs.ProviderName)
Next i
End Sub
注解
ConnectionStringSettingsCollection 对象包含 ConnectionStringSettings 对象的集合。 每个 ConnectionStringSettings 对象表示 <connectionStrings> 配置文件部分中的单个条目。
构造函数
| ConnectionStringSettingsCollection() |
初始化 ConnectionStringSettingsCollection 类的新实例。 |
属性
方法
显式接口实现
| ICollection.CopyTo(Array, Int32) |
将 ConfigurationElementCollection 复制到数组。 (继承自 ConfigurationElementCollection) |
扩展方法
| Cast<TResult>(IEnumerable) |
将 IEnumerable 的元素强制转换为指定类型。 |
| OfType<TResult>(IEnumerable) |
根据指定类型筛选 IEnumerable 的元素。 |
| AsParallel(IEnumerable) |
启用查询的并行化。 |
| AsQueryable(IEnumerable) |
将 IEnumerable 转换为 IQueryable。 |