Variables.Remove(Object) 메서드

정의

Variable 컬렉션에서 Variables 개체를 제거합니다.

public:
 void Remove(System::Object ^ index);
public void Remove (object index);
member this.Remove : obj -> unit
Public Sub Remove (index As Object)

매개 변수

index
Object

컬렉션에서 제거할 Variable 개체의 이름, ID, 설명 또는 인덱스입니다.

예제

다음 코드 예제에서는 빈 패키지에 변수를 추가합니다. 변수의 이름은 myCustomVar3으로 지정되고 사용자 네임스페이스에 있습니다. 그런 다음 메서드를 사용하여 변수가 Remove 제거됩니다.

using System;  
using System.Collections.Generic;  
using System.Text;  
using Microsoft.SqlServer.Dts.Runtime;  

namespace Add_Remove_Vars  
{  
    class Program  
    {  
        static void Main(string[] args)  
        {  
            Package pkg = new Package();  
            Variables pkgVars = pkg.Variables;  
            Variable myVar = pkg.Variables.Add("myCustomVar", false, "User", "3");  

            // Verify whether the variable is in the collection now.  
            Boolean hasMyVar = pkg.Variables.Contains("myCustomVar");  
            Console.WriteLine("The variable was found? {0}", hasMyVar);  

            Console.WriteLine("---------------------------");  
            // Loop over the collection using the foreach keyword.  
            foreach (Variable pkgVar in pkgVars)  
            {  
                // Print variables only from the User namespace.  
                if (pkgVar.Namespace == "User")  
                {  
                Console.WriteLine("Variable: {0}, {1}", pkgVar.Name, pkgVar.Value.ToString());  
                 }  
            }  
            Console.WriteLine("---------------------------");  
            // Remove the variable from the namespace.  
            pkg.Variables.Remove("myCustomVar");  

            // Loop over the collection again.  
            foreach (Variable pkgVar in pkgVars)  
            {  
                // Print variables only from the User namespace. Nothing should show.  
                if (pkgVar.Namespace == "User")  
                {  
                    Console.WriteLine("Variable: {0}, {1}", pkgVar.Name, pkgVar.Value.ToString());  
                }  
            }  
            Console.WriteLine("---------------------------");  
            Console.WriteLine("");  
        }  
    }  
}  
Imports System  
Imports System.Collections.Generic  
Imports System.Text  
Imports Microsoft.SqlServer.Dts.Runtime  

Namespace Add_Remove_Vars  
    Class Program  
        Shared  Sub Main(ByVal args() As String)  
            Dim pkg As Package =  New Package()   
            Dim pkgVars As Variables =  pkg.Variables   
            Dim myVar As Variable =  pkg.Variables.Add("myCustomVar",False,"User","3")   

            ' Verify whether the variable is in the collection now.  
            Dim hasMyVar As Boolean =  pkg.Variables.Contains("myCustomVar")   
            Console.WriteLine("The variable was found? {0}", hasMyVar)  

            Console.WriteLine("---------------------------")  
            ' Loop over the collection using the foreach keyword.  
            Dim pkgVar As Variable  
            For Each pkgVar In pkgVars  
                ' Print variables only from the User namespace.  
                If pkgVar.Namespace = "User" Then  
                Console.WriteLine("Variable: {0}, {1}", pkgVar.Name, pkgVar.Value.ToString())  
                End If  
            Next  
            Console.WriteLine("---------------------------")  
            ' Remove the variable from the namespace.  
            pkg.Variables.Remove("myCustomVar")  

            ' Loop over the collection again.  
            Dim pkgVar As Variable  
            For Each pkgVar In pkgVars  
                ' Print variables only from the User namespace. Nothing should show.  
                If pkgVar.Namespace = "User" Then  
                    Console.WriteLine("Variable: {0}, {1}", pkgVar.Name, pkgVar.Value.ToString())  
                End If  
            Next  
            Console.WriteLine("---------------------------")  
            Console.WriteLine("")  
        End Sub  
    End Class  
End Namespace  

샘플 출력:

변수가 발견되었나요? 참

---------------------------

변수: myCustomVar, 3

---------------------------

---------------------------

적용 대상