c# - Using LINQ to get a distinct list of Parameters from a list of objects -
Then I have a list of reports, and each report object has parameter collection
(which is < Code> archive ) containing each parameter
in that collection. I would like to get unique parameters in all reports.
I have already had to work through long-lasting (potentially incompetent) way through looping through each report in the list and then looping through each parameter in the collection in a temp list and Then using . Distinct ()
On that, but I thought LINQ was a better way but I can not find it at all. Select ()
and SelectMany ()
.
Any ideas? Thanks!
The original code
var reportParam = Selected Reports.Ougination (RPT = & gt; RPT .name, RPT = & gt; RPT. Parameter); Var uniqueParams = New Dictionary & lt; String, Parameter & gt; (); Foreach (Var Collection in Report.Parsams.Values) {foreach (Paramator Ultimate in the Collection) {If (! Unique Param Containssequi (Ultimate. Name)) Exclusive Mercury Add (param.Name, param); }} Var Last Collection = New Parameter Collection (); Fourte (exclusive absolute value in various params. Distinction ()) {Last Selection. Ad (the ultimate); } Selection of final return;
var unique params = report. SelectionMoni (Report => Report Parameters) .Distinct ();
Edit:
var uniqueParams = Report. SelectMonny (Report => Report Parameters. CAST & lt; Parameters & gt; ()). Specific ();
Comments
Post a Comment