using System; using System.Collections.Generic; class Program { static void Main(string[] args) { Dictionarydict = new Dictionary (); dict.Add("apple", 5); dict.Add("banana", 2); string key1 = "apple"; string key2 = "orange"; bool hasKey1 = dict.ContainsKey(key1); bool hasKey2 = dict.ContainsKey(key2); Console.WriteLine(hasKey1); // Output: True Console.WriteLine(hasKey2); // Output: False } }
using System; using System.Linq; class Program { static void Main(string[] args) { int[] nums = { 1, 2, 3, 4, 5 }; int key1 = 3; int key2 = 6; bool hasKey1 = nums.Contains(key1); bool hasKey2 = nums.Contains(key2); Console.WriteLine(hasKey1); // Output: True Console.WriteLine(hasKey2); // Output: False } }In this example, we create a slice of integers and use the Slice ContainsKey method to check if 3 and 6 exist in the slice. The package library for C# Slice ContainsKey is the System.Linq package.