Skip to content

Latest commit

 

History

History
54 lines (37 loc) · 2.43 KB

README.md

File metadata and controls

54 lines (37 loc) · 2.43 KB

CI CD C# Issues Commit License NuGet

net20 net462 net60 net80

BB84.Extensions

A collection of some random C# extensions I needed in many projects.

Usage

Depending on the application, there are several ways to skin a cat.

Example extensions

Start of week

The StartOfWeek method returns the first day of the week using the specified date and the definition of the first day of the week.

DateTime today = new(2023, 9, 5);
DateTime startOfWeek = today.StartOfWeek();

Random choice

The TakeRandom method returns a randomly chosen item from a given array.

int[] ints = [1, 2, 3];
int i = ints.TakeRandom();

For each

The ForEach method iterates over an enumerable and executes an action on each element.

int hits = default;
IEnumerable<string> strings = ["a", "ab", "b", "bb"];
strings.ForEach(x => x.Contains("a"), x => hits++);

Documentation

The complete API documentation can be found here.