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 8308899
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T18:56:37+00:00 2026-06-08T18:56:37+00:00

I am trying to make a struct for a range variable (minimum, maximum) with

  • 0

I am trying to make a struct for a range variable (minimum, maximum) with a few members and a method to know if between values.

Right now my struct looks like this:

public struct NumRange
{
    float maximum;
    float minimum;

    public NumRange(float min, float max) 
    {
        this.maximum = max;
        this.minimum = min;
    }

    public bool IsBetween(float value)
    {
        if (value < maximum && value > minimum)
            return true;

        return false;
    }
}

I want to be able to make number ranges by

NumRange test = new NumRange(15, 20);

The whole point of making this range variable type is to make a map key dictionary like:

public Dictionary<NumRange, Color> mapKey = new Dictionary<NumRange, Color>();
NumRange test = new NumRange(15, 20);
mapKey.Add(test, Color.Orange);

Is this the best way to go about it? Also it doesn’t like when I try to add something to mapKey. Says there is invalid tokens such as ‘,’ ‘)’ ‘(‘

  • 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-08T18:56:39+00:00Added an answer on June 8, 2026 at 6:56 pm

    Unless you have a finite number of values to look up, a dictionary may not be the best choice. It looks like you’re mapping ranges of values to colors to apply to a height map. This stub of a class will let you do so, but note that it does not accommodate blending from color A to color B.

    class RangeMap<T>
    {
        private SortedList<float, T>  _values;
    
        public RangeMap()
        {
            _values = new SortedList<float, T>();
        }
    
        public void AddPoint(float max, T value)
        {
            _values[max] = value;
        }
    
        public T GetValue(float point)
        {
            if (_values.ContainsKey(point)) return _values[point];
    
            return (from kvp in _values where kvp.Key > point select kvp.Value)
                   .FirstOrDefault();
        }
    }   
    
    var  map = new RangeMap<Color>();
    map.AddPoint(0.0F, Color.Red);
    map.AddPoint(0.5F, Color.Green);
    map.AddPoint(1.0F, Color.Blue);
    
    Console.WriteLine(map.GetValue(-0.25F).Name);
    Console.WriteLine(map.GetValue( 0.25F).Name);
    Console.WriteLine(map.GetValue( 0.75F).Name);
    Console.WriteLine(map.GetValue( 1.25F).Name);
    

    Output: Red, Green, Blue, empty struct.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to make a struct that generates a random matrix and am getting
I'm very new to F# and I'm trying to make a struct for storing
I am trying to make a simple Queue class. Now I am stuck. Its
I'm trying to make a search method using a binary tree(no, it's not a
I'm new in html5 and its websocket! now I've been trying to make my
I am trying to make a struct with a default value, as described here:
I am trying to make a struct which has a function pointer for a
I'm trying to make it easy for me to move binary data between Perl
I am trying to make a method to enumerate any enum , by returning
I'm trying to create a struct used in two .c source files to make

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.