Structr
  • Welcome
  • Utilities
    • Abstractions
      • Check
      • Ensure
      • Money
      • HierarchyId
      • Providers
        • SequentialGuidProvider
      • Extensions
        • DateTime
        • Dictionary
        • DirectoryInfo
        • Enumerable
        • Enum
        • Expression
        • Int
        • Long
        • MemberInfo
        • Object
        • Queryable
        • ServiceCollection
        • String
        • Type
      • Helpers
        • AsyncHelper
        • BindHelper
      • JsonConverters
        • DateOnly
        • TimeOnly
        • StringNumber
    • Collections
      • AutoMapper extensions
    • IO
      • FileHelper
      • MimeTypeHelper
      • PathHelper
      • SequentialFileName
    • Configuration
      • Providers
        • JSON-file
        • XML-file
        • In-Memory
        • Consul
      • Get settings
      • Set settings
      • Customization
    • Email
      • Razor
    • Navigation
      • Menu
      • Breadcrumbs
    • Security
  • Domain
    • Domain
      • Entities
      • Value objects
  • Data Access
    • Entity Framework Core
    • Entity Framework 6
  • Use Cases
    • Operations
      • Filtering
      • Decoration
    • Notices
    • Validation
    • Specifications
    • Stateflows
      • StateMachine
      • Configurations
  • Presentation
    • ASP.NET Core
      • Client
      • Http
      • JavaScript
      • Json
      • Mvc
      • Referrer
      • Rewrite
      • Routing
      • TagHelpers
      • Validation
Powered by GitBook
On this page
  • AddRangeOverride
  • AddRangeNewOnly
  • AddRange
  • ContainsKeys

Was this helpful?

Edit on GitHub
  1. Utilities
  2. Abstractions
  3. Extensions

Dictionary

AddRangeOverride

Adds new values to source dictionary, overriding values for existing keys.

var dictionary = new Dictionary<int, string>
{
    { 1, "One" },
    { 2, "Two" },
    { 3, "Three" },
    { 4, "Four" }
};
var newDictionary = new Dictionary<int, string>
{
    { 1, "One_overridden" },
    { 3, "Three_overridden" },
    { 5, "Five_new" }
};
dictionary.AddRangeOverride(newDictionary);

// results in:
//  { 1, "One_overridden" },
//  { 2, "Two" },
//  { 3, "Three_overridden" },
//  { 4, "Four" },
//  { 5, "Five_new" }

AddRangeNewOnly

Adds new values to source dictionary, leaving existing keys values untouched.

var dictionary = new Dictionary<int, string>
{
    { 1, "One" },
    { 2, "Two" },
    { 3, "Three" },
    { 4, "Four" }
};
var newDictionary = new Dictionary<int, string>
{
    { 1, "One_don`t_override" },
    { 3, "Three_don`t_override" },
    { 5, "Five_new" }
};
dictionary.AddRangeNewOnly(newDictionary);

// results in:
//  { 1, "One" },
//  { 2, "Two" },
//  { 3, "Three" },
//  { 4, "Four" },
//  { 5, "Five_new" }

AddRange

Adds new values to source dictionary. Throws if one or more keys in new list already exist in source dictionary.

var dictionary = new Dictionary<int, string>
{
    { 1, "One" },
    { 2, "Two" },
    { 3, "Three" },
    { 4, "Four" }
};
var newDictionary = new Dictionary<int, string>
{
    { 5, "Five_new" }
    { 6, "Six_new" }
};
dictionary.AddRange(newDictionary);

// results in:
//  { 1, "One" },
//  { 2, "Two" },
//  { 3, "Three" },
//  { 4, "Four" },
//  { 5, "Five_new" }
//  { 6, "Six_new" }

ContainsKeys

Checks if at least one key from provided list exists in source dictionary.

var dictionary = new Dictionary<int, string>
{
    { 1, "One" },
    { 2, "Two" },
    { 3, "Three" },
    { 4, "Four" }
};
var result = dictionary.ContainsKeys(new int[] { 1, 2, 3 }); // true
result = dictionary.ContainsKeys(new int[] { 4, 5 }); // true
result = dictionary.ContainsKeys(new int[] { 6, 7 }); // false
PreviousDateTimeNextDirectoryInfo

Last updated 2 years ago

Was this helpful?