IDataPacker.ContainsKey(string key) Method
.NET Standard 2.x
Checks whether a specified element exists in the current IDataPacker
object.
Namespace: SnapObjects.Data
Assembly: SnapObjects.Data.dll
Syntax
bool ContainsKey(string key);
Parameters
key
System.String
The key of the element to look for.
Returns
System.Boolean
Returns true
if the element exists; otherwise, false
.
Examples
The following code example adds two keys and values to the IDataPacker
object and then checks if one of the keys exists in IDataPacker
.
using SnapObjects.Data;
using System;
namespace Appeon.ApiDoc.IDataPackerExamples
{
public class ContainsKeyExample
{
private readonly SchoolContext _context;
public ContainsKeyExample(SchoolContext dataContext)
{
// Sets the data context.
_context = dataContext;
}
public void Example()
{
var packer = new DataPacker();
// Adds the key "FirstParam" and its value "NameValue1" to DataPacker
// Adds the key "SecondParam" and its value "NameValue2" to DataPacker
packer.AddValue("FirstParam", "NameValue1");
packer.AddValue("SecondParam", "NameValue2");
// Gets and shows the number of elements in IDataPacker
Console.WriteLine("The element count: {0}", packer.Count.ToString());
// Checks if the key name "FirstParam" exists in IDataPacker and returns true
Console.WriteLine(packer.ContainsKey("FirstParam"));
// Checks if the key name "Other" exists in IDataPacker and returns false
Console.WriteLine(packer.ContainsKey("Other"));
/* This code example produces the following output:
The element count: 2
True
False
*/
}
}
}
Applies to
.NET Standard
2.x