Show / Hide Table of Contents

    IDataPacker.RemoveKey(string key) Method

    .NET Standard 2.x

    Removes the specified element from the IDataPacker object.

    Namespace: SnapObjects.Data

    Assembly: SnapObjects.Data.dll

    Syntax

    bool RemoveKey(string key);
    

    Parameters

    key System.String

    The key of the element to remove.

    Returns

    System.Boolean

    Returns true if the element is successfully removed; returns false if the element was not found.

    Examples

    The following code example removes the specified key from the IDataPacker object.

    using SnapObjects.Data;
    using System;
    
    namespace Appeon.ApiDoc.IDataPackerExamples
    {
        public class RemoveKeyExample
        {
            private readonly SchoolContext _context;
    
            public RemoveKeyExample(SchoolContext dataContext)
            {
                // Sets the data context.
                _context = dataContext;
            }
    
            public void Example()
            {
                var packer = new DataPacker();
    
                // Adds "NameValue1" and key name "FirstParam" to IDataPacker
                // Adds "NameValue2" and key anme "SecondParam" to IDataPacker
                packer.AddValue("FirstParam", "NameValue1");
                packer.AddValue("SecondParam", "NameValue2");
    
                // Gets and shows the number of elements in IDataPacker
                Console.WriteLine("Before delete, the element count: {0}", 
                    packer.Count.ToString());
    
                Console.WriteLine(packer.GetTextString(DataFormat.Json));
    
                // Removes the element whose key name is "FirstParam"
                packer.RemoveKey("FirstParam");
    
                // Gets and shows the number of elements in IDataPacker
                Console.WriteLine("After delete, the element count: {0}", 
                    packer.Count.ToString());
    
                // Gets and shows the data values in JSON format
                Console.WriteLine(packer.GetTextString(DataFormat.Json));
    
                /* This code example produces the following output:
                
                Before delete, the element count: 2
                {"FirstParam":"NameValue1","SecondParam":"NameValue2"}
                After delete, the element count: 1
                {"SecondParam":"NameValue2"}
                */
            }
        }
    }
    

    Applies to

    .NET Standard

    2.x

    Back to top Generated by Appeon