Reputation: 1988
I have the following class:
using System;
using System.Collections.Generic;
namespace ddd
{
public class FPSData
{
private double minFPS;
private double maxFPS;
private double averageFPS;
#region Properties
public double MinFPS
{
get { return minFPS; }
set { minFPS = value; }
}
public double MaxFPS
{
get { return maxFPS; }
set { maxFPS = value; }
}
public double AverageFPS
{
get { return averageFPS; }
set { averageFPS = value; }
}
#endregion Properties
public FPSData(double min, double max, double avg)
{
minFPS = min;
maxFPS = max;
averageFPS = avg;
}
}
}
In my main function, I'm declaring the following:
class Program
{
static void Main(string[] args)
{
Dictionary<uint, FPSData> trying = new Dictionary<uint, FPSData>();
FPSData m1 = new FPSData(1, 2, 3);
FPSData m2 = new FPSData(4, 5, 6);
FPSData m3 = new FPSData(7, 8, 9);
trying.Add(101, m1);
trying.Add(102, m2);
trying.Add(103, m3);
Console.WriteLine("sdfgh");
}
}
I'm trying to get a dictionary (Dictionary<uint, doubule>
) for, let's say, only the minimum values.
Meaning, that my dictionary will have the following:
101, 1
102, 4
103, 7
I tried many variations of LINQ
, but just couldn't get it right. Is it possible?
Upvotes: 0
Views: 69
Reputation: 53958
Dictionary<uint, double> result = trying.ToDictionary(x=>x.Key,x=>x.Value.MinFPS);
Upvotes: 2
Reputation: 4183
Do this:
Dictionary<uint, double> minimumFPS = trying.ToDictionary(k => k.Key, v => v.Value.MinFPS);
Upvotes: 1
Reputation: 6304
Use .ToDictionary()
(MSDN Documentation):
var minimumValues = trying.ToDictionary(k => k.Key, v => v.Value.MinFPS);
Upvotes: 4