Skip to content

castilhera/csharp-code-snippets

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 

Repository files navigation

C# Code Snippets

A bunch of random C# code snippets that might help.

Extensions

Date Extensions

IsWeekend
Check if DayOfWeek is Saturday or Sunday. (Note: This does not apply to all countries and cultures. I found it useful for Brazil.)
ToFirstDayOfMonth
Returns the first day of the month for the specified DateOnly/DateTime/DateTimeOffset.
ToLastDayOfMonth
Returns the last day of the month for the specified DateOnly/DateTime/DateTimeOffset.
GetIso8601WeekNumber
Returns the week of the year, according to ISO-8601, for the specified DateTime.

Stream Extensions

ReadLinesAsync
Returns an iterator to read a stream line by line

String Extensions

Reverse
Reverses a given string. e.g. ABCD => DCBA
ToSnakeCase
Convert string to snake_case format. e.g. CodeSnippets => code_snippets

Helpers

Validation Helpers

IsValidCnpj
Check if the given string is a valid CNPJ.
IsValidCpf
Check if the given string is a valid CPF.