共用方式為


PagesSection.Namespaces 屬性

定義

取得 NamespaceInfo 物件的集合。

public:
 property System::Web::Configuration::NamespaceCollection ^ Namespaces { System::Web::Configuration::NamespaceCollection ^ get(); };
[System.Configuration.ConfigurationProperty("namespaces")]
public System.Web.Configuration.NamespaceCollection Namespaces { get; }
[<System.Configuration.ConfigurationProperty("namespaces")>]
member this.Namespaces : System.Web.Configuration.NamespaceCollection
Public ReadOnly Property Namespaces As NamespaceCollection

屬性值

NamespaceCollection

NamespaceCollection 物件的 NamespaceInfo

屬性

範例

下列程式碼範例示範如何使用 Namespaces 屬性。

       // Get the AutoImportVBNamespace property.
       Console.WriteLine("AutoImportVBNamespace: '{0}'",
           pagesSection.Namespaces.AutoImportVBNamespace.ToString());

       // Set the AutoImportVBNamespace property.
       pagesSection.Namespaces.AutoImportVBNamespace = true;

       // Get all current Namespaces in the collection.
       for (int i = 0; i < pagesSection.Namespaces.Count; i++)
       {
         Console.WriteLine(
             "Namespaces {0}: '{1}'", i,
             pagesSection.Namespaces[i].Namespace);
       }

       // Create a new NamespaceInfo object.
       System.Web.Configuration.NamespaceInfo namespaceInfo =
           new System.Web.Configuration.NamespaceInfo("System");

       // Set the Namespace property.
       namespaceInfo.Namespace = "System.Collections";

       // Execute the Add Method.
       pagesSection.Namespaces.Add(namespaceInfo);

       // Add a NamespaceInfo object using a constructor.
       pagesSection.Namespaces.Add(
           new System.Web.Configuration.NamespaceInfo(
           "System.Collections.Specialized"));

       // Execute the RemoveAt method.
       pagesSection.Namespaces.RemoveAt(0);

       // Execute the Clear method.
       pagesSection.Namespaces.Clear();

       // Execute the Remove method.
       pagesSection.Namespaces.Remove("System.Collections");

       // Get the current AutoImportVBNamespace property value.
       Console.WriteLine(
           "Current AutoImportVBNamespace value: '{0}'",
           pagesSection.Namespaces.AutoImportVBNamespace);

       // Set the AutoImportVBNamespace property to false.
       pagesSection.Namespaces.AutoImportVBNamespace = false;
' Get the AutoImportVBNamespace property.
Console.WriteLine( _
 "AutoImportVBNamespace: '{0}'", _
 pagesSection.Namespaces.AutoImportVBNamespace)

' Set the AutoImportVBNamespace property.
pagesSection.Namespaces.AutoImportVBNamespace = True

' Get all current Namespaces in the collection.
Dim i As Int16
For i = 0 To pagesSection.Namespaces.Count - 1
  Console.WriteLine( _
   "Namespaces {0}: '{1}'", i, _
   pagesSection.Namespaces(i).Namespace)
Next

' Create a new NamespaceInfo object.
Dim namespaceInfo As System.Web.Configuration.NamespaceInfo = _
 New System.Web.Configuration.NamespaceInfo("System")

' Set the Namespace property.
namespaceInfo.Namespace = "System.Collections"

' Execute the Add Method.
pagesSection.Namespaces.Add(namespaceInfo)

' Add a NamespaceInfo object using a constructor.
pagesSection.Namespaces.Add( _
 New System.Web.Configuration.NamespaceInfo( _
 "System.Collections.Specialized"))

' Execute the RemoveAt method.
pagesSection.Namespaces.RemoveAt(0)

' Execute the Clear method.
pagesSection.Namespaces.Clear()

' Execute the Remove method.
pagesSection.Namespaces.Remove("System.Collections")

' Get the current AutoImportVBNamespace property value.
Console.WriteLine( _
 "Current AutoImportVBNamespace value: '{0}'", _
 pagesSection.Namespaces.AutoImportVBNamespace)

' Set the AutoImportVBNamespace property to false.
pagesSection.Namespaces.AutoImportVBNamespace = False

備註

物件 TagPrefixInfo 會對應至 @ Import ASP.NET 網頁上的 指示詞。 指示 Import 詞可讓您指定自動匯入應用程式所有頁面的命名空間。

適用於

另請參閱