Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8001641
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T16:08:31+00:00 2026-06-04T16:08:31+00:00

private readonly ConcurrentDictionary<string, System.Drawing.Color> _colorSet; public void BuildColorSet(IList<string> colorNames, string prefix, bool forceLastToGray) {

  • 0
private readonly ConcurrentDictionary<string, System.Drawing.Color> _colorSet;      

public void BuildColorSet(IList<string> colorNames, string prefix, bool forceLastToGray)
{
    var size = forceLastToGray ? colorNames.Count - 1 : colorNames.Count;

    int nbHue = 6;
    int nbCycle = (int)Math.Ceiling((double)size / nbHue);

    var saturationMax = nbCycle <= 2 ? 1.0 : 1.0;
    var saturationMin = 0.3;
    var luminanceMax = nbCycle <= 2 ? 0.85 : 0.85;
    var luminanceMin = 0.3;
    var maxSaturationShift = 0.30;
    var maxLuminanceShift = 0.15;

    var interval = 1.0 / Math.Min(size, nbHue);

    var saturationShift = (saturationMax - saturationMin) / (nbCycle - 1);
    saturationShift = Math.Min(saturationShift, maxSaturationShift);
    var luminanceShift = (luminanceMax - luminanceMin) / (nbCycle - 1);
    luminanceShift = Math.Min(luminanceShift, maxLuminanceShift);

    var hueShift = 0.0;

    var saturation = saturationMax;
    var luminance = luminanceMax;
    for(var i = 0; i<size; i++)
    {
        if(i > 0 && (i % nbHue == 0)) // Next Cycle
        {
            saturation -= saturationShift;
            luminance -= luminanceShift;
            hueShift = hueShift == 0 ? interval/2 : 0;
        }
        var hue = interval*(i%nbHue) + hueShift;

        System.Drawing.Color color = HSL2RGB(hue, saturation, luminance);

    _colorSet.AddOrUpdate(prefix + colorNames[i], color, ???);
    }
    if(forceLastToGray)
    {
        _colorSet.TryAdd(prefix + colorNames[colorNames.Count - 1], System.Drawing.Color.LightGray);
    }

    _cssDirty = true;
}

I want to be able to update the dictionary if the color exists with new value. And also add to dictionary if the color is not there in dictionary.
I am using the AddOrUpdate but not able to get the 3rd parameter(form the lambda expression OR delegate method) of the AddOrUpdate method.
Any idea how my 3rd parameter would look like?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T16:08:31+00:00Added an answer on June 4, 2026 at 4:08 pm

    From the documentation:

    updateValueFactory
    Type: System.Func
    The function used to generate a new value for an existing key based on the key’s existing value

    This will leave the value in the collection alone if it already exists:

    _colorSet.AddOrUpdate(prefix + colorNames[i], color,
                (key, existingVal) =>
                {
                    return existingVal;
                });
    

    This will replace the value in the collection with the same one specified for the insert:

    _colorSet.AddOrUpdate(prefix + colorNames[i], color,
                (key, existingVal) =>
                {
                    return color;
                });
    

    You can perform conditional logic, comparisons between the old value and new value, or update the original object in the function, for example.

    _colorSet.AddOrUpdate(prefix + colorNames[i], color,
                (key, existingVal) =>
                {
                    if (existingVal.Name == "Red")
                        return existingVal;
                    else
                        return color;
                });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here's what I have private readonly Dictionary<Type, List<object>> _cache; public IList<T> Get<T> (Expression<Func<T, bool>>
public class ComEffectColor : ComEffectBase<Ref<Color>> { private readonly Color finalColor; private Color originalColor; public
I have the following domain model: public class Name { private readonly string fullName;
This is my model class. public class Lead { private readonly ObservableCollection<String> m_tags =
I have the following code : public class MyClass { private readonly string name;
class Unit { private readonly string name; private readonly double scale; public Unit(string name,
Consider the following code : public class RandomClass { private readonly string randomString; public
class InspectionEquip : DataSet { private readonly SqlConnection CPEC = new SqlConnection(ConfigurationManager.ConnectionStrings[ConnectionString].ToString()); public InspectionEquip(string
Having the following class: public class SomeClass { private readonly int[] _someThings; public SomeClass()
I use razor engine like this: public class EmailService : IService { private readonly

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.