|
400 | 400 | </Attributes> |
401 | 401 | </Parameter> |
402 | 402 | </Parameters> |
403 | | - <Docs> |
404 | | - <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam> |
405 | | - <typeparam name="TKey">The type of the key returned by <paramref name="keySelector" />.</typeparam> |
406 | | - <typeparam name="TAccumulate">The type of the accumulator value.</typeparam> |
407 | | - <param name="source">An <see cref="T:System.Collections.Generic.IEnumerable`1" /> to aggregate over.</param> |
408 | | - <param name="keySelector">A function to extract the key for each element.</param> |
409 | | - <param name="seedSelector">A factory for the initial accumulator value.</param> |
410 | | - <param name="func">An accumulator function to be invoked on each element.</param> |
411 | | - <param name="keyComparer">An <see cref="T:System.Collections.Generic.IEqualityComparer`1" /> to compare keys with.</param> |
412 | | - <summary>Applies an accumulator function over a sequence, grouping results by key.</summary> |
413 | | - <returns>An enumerable containing the aggregates corresponding to each key deriving from <paramref name="source" />.</returns> |
414 | | - <remarks> |
415 | | - This method is comparable to the <see cref="M:System.Linq.Enumerable.GroupBy``2(System.Collections.Generic.IEnumerable{``0},System.Func{``0,``1})" /> methods where each grouping is being aggregated into a single value as opposed to allocating a collection for each group. |
416 | | - </remarks> |
417 | | - <example> |
418 | | - <para> |
419 | | - The following example demonstrates how to use AggregateBy with a seed selector to compute multiple values per key. |
420 | | - </para> |
421 | | - <code language="csharp"> |
422 | | - class Employee |
423 | | - { |
424 | | - public string Name { get; set; } |
425 | | - public string Department { get; set; } |
426 | | - public decimal Salary { get; set; } |
427 | | - } |
428 | | - |
429 | | - public static void AggregateBySeedSelectorExample() |
430 | | - { |
431 | | - Employee[] employees = |
432 | | - { |
433 | | - new Employee { Name = "Ali", Department = "HR", Salary = 45000 }, |
434 | | - new Employee { Name = "Samer", Department = "Technology", Salary = 50000 }, |
435 | | - new Employee { Name = "Hamed", Department = "Sales", Salary = 75000 }, |
436 | | - new Employee { Name = "Lina", Department = "Technology", Salary = 65000 }, |
437 | | - new Employee { Name = "Omar", Department = "HR", Salary = 40000 } |
438 | | - }; |
439 | | - |
440 | | - var result = |
441 | | - employees.AggregateBy( |
442 | | - e => e.Department, |
443 | | - dept => (Total: 0m, Count: 0), |
444 | | - (acc, e) => (acc.Total + e.Salary, acc.Count + 1) |
445 | | - ); |
446 | | - |
447 | | - foreach (var item in result) |
448 | | - { |
449 | | - Console.WriteLine($"{item.Key}: Total={item.Value.Total}, Count={item.Value.Count}"); |
450 | | - } |
451 | | - } |
452 | | - |
453 | | - /* |
454 | | - This code produces the following output: |
455 | | - |
456 | | - HR: Total=85000, Count=2 |
457 | | - Technology: Total=115000, Count=2 |
458 | | - Sales: Total=75000, Count=1 |
459 | | - */ |
460 | | - </code> |
461 | | - </example> |
| 403 | + <Docs> |
| 404 | + <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam> |
| 405 | + <typeparam name="TKey">The type of the key returned by <paramref name="keySelector" />.</typeparam> |
| 406 | + <typeparam name="TAccumulate">The type of the accumulator value.</typeparam> |
| 407 | + <param name="source">An <see cref="T:System.Collections.Generic.IEnumerable`1" /> to aggregate over.</param> |
| 408 | + <param name="keySelector">A function to extract the key for each element.</param> |
| 409 | + <param name="seedSelector">A factory for the initial accumulator value.</param> |
| 410 | + <param name="func">An accumulator function to be invoked on each element.</param> |
| 411 | + <param name="keyComparer">An <see cref="T:System.Collections.Generic.IEqualityComparer`1" /> to compare keys with.</param> |
| 412 | + <summary>Applies an accumulator function over a sequence, grouping results by key.</summary> |
| 413 | + <returns>An enumerable containing the aggregates corresponding to each key deriving from <paramref name="source" />.</returns> |
| 414 | + <remarks> |
| 415 | + <format type="text/markdown"><![CDATA[ |
| 416 | + |
| 417 | +## Remarks |
| 418 | + |
| 419 | +This method is comparable to the <xref:System.Linq.Enumerable.GroupBy%2A> methods where each grouping is being aggregated into a single value as opposed to allocating a collection for each group. |
| 420 | + |
| 421 | +## Examples |
| 422 | + |
| 423 | +The following example demonstrates how to use `AggregateBy` with a seed selector to compute multiple values per key. |
| 424 | + |
| 425 | +:::code language="csharp" source="~/snippets/csharp/System.Linq/Enumerable/AggregateTSource/enumerable.cs" id="Snippet205"::: |
| 426 | + |
| 427 | + ]]></format> |
| 428 | + </remarks> |
462 | 429 | </Docs> |
463 | 430 | </Member> |
464 | 431 | <Member MemberName="AggregateBy<TSource,TKey,TAccumulate>"> |
|
523 | 490 | </Parameter> |
524 | 491 | </Parameters> |
525 | 492 | <Docs> |
526 | | - <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam> |
527 | | - <typeparam name="TKey">The type of the key returned by <paramref name="keySelector" />.</typeparam> |
528 | | - <typeparam name="TAccumulate">The type of the accumulator value.</typeparam> |
529 | | - <param name="source">An <see cref="T:System.Collections.Generic.IEnumerable`1" /> to aggregate over.</param> |
530 | | - <param name="keySelector">A function to extract the key for each element.</param> |
531 | | - <param name="seed">The initial accumulator value.</param> |
532 | | - <param name="func">An accumulator function to be invoked on each element.</param> |
533 | | - <param name="keyComparer">An <see cref="T:System.Collections.Generic.IEqualityComparer`1" /> to compare keys with.</param> |
534 | | - <summary>Applies an accumulator function over a sequence, grouping results by key.</summary> |
535 | | - <returns>An enumerable containing the aggregates corresponding to each key deriving from <paramref name="source" />.</returns> |
536 | | - <remarks> |
537 | | - This method is comparable to the <see cref="M:System.Linq.Enumerable.GroupBy``2(System.Collections.Generic.IEnumerable{``0},System.Func{``0,``1})" /> methods where each grouping is being aggregated into a single value as opposed to allocating a collection for each group. |
538 | | - </remarks> |
539 | | - <example> |
540 | | - <para> |
541 | | - The following example demonstrates how to use AggregateBy with a constant seed value to compute totals per key. |
542 | | - </para> |
543 | | - <code language="csharp"> |
544 | | - class Employee |
545 | | - { |
546 | | - public string Name { get; set; } |
547 | | - public string Department { get; set; } |
548 | | - public decimal Salary { get; set; } |
549 | | - } |
550 | | - |
551 | | - public static void AggregateBySeedExample() |
552 | | - { |
553 | | - Employee[] employees = |
554 | | - { |
555 | | - new Employee { Name = "Ali", Department = "HR", Salary = 45000 }, |
556 | | - new Employee { Name = "Samer", Department = "Technology", Salary = 50000 }, |
557 | | - new Employee { Name = "Hamed", Department = "Sales", Salary = 75000 }, |
558 | | - new Employee { Name = "Lina", Department = "Technology", Salary = 65000 }, |
559 | | - new Employee { Name = "Omar", Department = "HR", Salary = 40000 } |
560 | | - }; |
561 | | - |
562 | | - // Compute total salary per department using a constant seed |
563 | | - var totals = |
564 | | - employees.AggregateBy( |
565 | | - e => e.Department, |
566 | | - 0m, |
567 | | - (total, e) => total + e.Salary |
568 | | - ); |
569 | | - |
570 | | - foreach (var item in totals) |
571 | | - { |
572 | | - Console.WriteLine($"{item.Key}: {item.Value}"); |
573 | | - } |
574 | | - } |
575 | | - |
576 | | - /* |
577 | | - This code produces the following output: |
578 | | - |
579 | | - HR: 85000 |
580 | | - Technology: 115000 |
581 | | - Sales: 75000 |
582 | | - */ |
583 | | - </code> |
584 | | - </example> |
585 | | - </Docs> |
| 493 | + <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam> |
| 494 | + <typeparam name="TKey">The type of the key returned by <paramref name="keySelector" />.</typeparam> |
| 495 | + <typeparam name="TAccumulate">The type of the accumulator value.</typeparam> |
| 496 | + <param name="source">An <see cref="T:System.Collections.Generic.IEnumerable`1" /> to aggregate over.</param> |
| 497 | + <param name="keySelector">A function to extract the key for each element.</param> |
| 498 | + <param name="seed">The initial accumulator value.</param> |
| 499 | + <param name="func">An accumulator function to be invoked on each element.</param> |
| 500 | + <param name="keyComparer">An <see cref="T:System.Collections.Generic.IEqualityComparer`1" /> to compare keys with.</param> |
| 501 | + <summary>Applies an accumulator function over a sequence, grouping results by key.</summary> |
| 502 | + <returns>An enumerable containing the aggregates corresponding to each key deriving from <paramref name="source" />.</returns> |
| 503 | + <remarks> |
| 504 | + <format type="text/markdown"><![CDATA[ |
| 505 | + |
| 506 | +## Remarks |
| 507 | + |
| 508 | +This method is comparable to the <xref:System.Linq.Enumerable.GroupBy%2A> methods where each grouping is being aggregated into a single value as opposed to allocating a collection for each group. |
| 509 | + |
| 510 | +## Examples |
| 511 | + |
| 512 | +The following example demonstrates how to use `AggregateBy` with a constant seed value to compute totals per key. |
| 513 | + |
| 514 | +:::code language="csharp" source="~/snippets/csharp/System.Linq/Enumerable/AggregateTSource/enumerable.cs" id="Snippe"::: |
| 515 | + |
| 516 | + ]]></format> |
| 517 | + </remarks> |
| 518 | + </Docs> |
586 | 519 | </Member> |
587 | 520 | <Member MemberName="All<TSource>"> |
588 | 521 | <MemberSignature Language="C#" Value="public static bool All<TSource> (this System.Collections.Generic.IEnumerable<TSource> source, Func<TSource,bool> predicate);" /> |
|
0 commit comments