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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T11:48:03+00:00 2026-06-17T11:48:03+00:00

I have created a 2-dimensional list and want to return the maximum value, the

  • 0

I have created a 2-dimensional list and want to return the maximum value, the minimum value, and the names that have the same index as these values.

This is what i did.

class Info
{
    private string stad;
    private double temperatur;

    public string Stad
    {
        get { return stad; }
        set { stad = value; }
    }

    public double Temperatur
    {
        get { return temperatur; }
        set { temperatur = value; }
    }
}

    static double SearchMax(List<Info> list)
    {
        if (list.Count == 0)
        {
            throw new InvalidOperationException("Tomt Lista");
        }
        double Temperatur = double.MinValue;
        foreach (Info temperatur in list)
        {
            if (temperatur.Temperatur > Temperatur)
            {
                Temperatur = temperatur.Temperatur;
            }        
        }
        return Temperatur;
    }

    static double SearchMin(List<Info> list)
    {
        if (list.Count == 0)
        {
            throw new InvalidOperationException("Tomt Lista");
        }
        double Tempertatur = double.MaxValue;
        foreach (Info temperatur in list)
        {
            if (temperatur.Temperatur < Tempertatur)
            {
                Tempertatur = temperatur.Temperatur;
            }
        }
        return Tempertatur;
    }

But what I get in return is only the maximum and minimum values, not the name of the city that the temperature is in.

Can anyone tell me or show me how to return both?

Thank you for all the help you provide but it just put me back to where I was before posting this up here. What I want is for the program to return both the city and the temperature in the city
i.e “Warmest city is Oslo and it’s 20 °C warm”
and not “Warmest city is consoleaplication.info”

edit:2
Thank you for all yours help and especialy Alex ^_^

  • 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-17T11:48:04+00:00Added an answer on June 17, 2026 at 11:48 am
    private static TempratureInfo FindHighestTemprature(IList<TempratureInfo> tempratures)
    {
        if(tempratures.Count == 0)
            throw new InvalidOperationException("tempratures");
    
        return tempratures.OrderByDescending(t => t.Temprature)
                          .First();
    }
    
    private static TempratureInfo FindLowestTemprature(IList<TempratureInfo> tempratures)
    {
        if (tempratures.Count == 0)
            throw new InvalidOperationException("tempratures");
    
        return tempratures.OrderBy(t => t.Temprature)
                          .First();
    }
    

    You can ammend your Info class to override ToString which will return the formatted string when you call either of the functions above when a string is expected, argument pass, variable assignment etc.

    internal class TempratureInfo
    {
        public string Name { get; set; }
        public double Temprature { get; set; }
    
        public override string ToString()
        {
            return string.Format("Temprature in {0} is currently {1}", Name, Temprature);
        }
    }
    

    Sample implementation:

    private static void Main(string[] args)
        {
            List<TempratureInfo> unitedKingdomTempratures = new List<TempratureInfo>()
                {
                    {new TempratureInfo() { Name = "Wales", Temprature = 10.0}},
                    {new TempratureInfo() { Name = "England", Temprature = 55.0}},
                    {new TempratureInfo() { Name = "Scotland", Temprature = 22.0}},
                    {new TempratureInfo() { Name = "Northen Ireland", Temprature = 4.0}}
                };
    
            Console.WriteLine("Hottest: " + FindHighestTemprature(unitedKingdomTempratures).Name);
            Console.WriteLine("Coldest: " + FindLowestTemprature(unitedKingdomTempratures).Name);
    
            Console.ReadLine();
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have 2 dimensional list created at runtime (the number of entries in either
I have created a JTree which shows a list of files. these files have
I have a multi dimensional array, like this: array('name' => array('title'=>'Title','date'=>'Created')) I store it
I have created some JQuery that will expand a div 'popup' on hover and
I have created an android application that calls (using kSOAP library) a SOAP based
I want to create two dimensional array of buttons in windows form. I have
Say I have a list: L = [2,5,1,8,3,7,9,4,6,10] or something similar And I want
i have a problem with my script i have a method that return a
I have a multi-dimensional array that looks like this: The base array is indexed
I have a multi-dimensional array that I am trying to feed into difflib.get_close_matches() .

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.