c# - Generic extension methods in LINQ -


Public Stable Class LinqExtensions {Public Stable Dual Variance (This IList & Lt; Double & gt; Data) {Double sumSquares = 0;

  double average = data. Average (); Forex currency (different numbers in data) {sumSquares + = (num - avg * num - avg); } Refund Amount / Statement (Data No. 1); } Public fixed decimals? Version & lt; TSource & gt; (This IEnumerable & lt; TSource & gt; source, function & lt; TSource, decimal? & Gt; selector) {// Where to start implementing? }}   

I want to create some LINQ extensions for the common type. I know how LINQ can be expanded without using delegates, I have many-just-defined types, which have the properties, which I need to compute and there are some variations from it. How can I define my variance extension method, so does it take a representative?

You can do this:

  Double Public Stabilize? Variance & lt; TSource & gt; (This IEnumerable & lt; TSource & gt; source, function & lt; TSource; double & gt; selector) {Double sumSquares = 0; Double average = source.verage (selector); Foreign object (different items in source) {var num = selector (item); SumSquares + = (num - avg * num - avg); } Refund amount / source (source.) - 1); }   

Bella is working with this sample -

UPDATE

Usage samples: < Public sector items {Public Double Val} {};}} Public Sector Program {Public Zero Main () {var items = new list & lt; Items & gt; (); item. Add (new item () {val = 1.1}); item. Add (new item () {val = 2.1}); item. Add (new item () {val = 3.1}); Var variance = items.Variance & lt; Items & gt; ((I) = & gt; i.Val); Console.WriteLine (variance); }}


Comments

Popular posts from this blog

eclipse plugin - Run java code error: Workspace is closed -

ios - How do I use CFArrayRef in Swift? -

scala - Play Framework - how to bind form to a session field -