Coder Social home page Coder Social logo

xgame92 / 30-seconds-of-c-sharp Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jonasschubert/30-seconds-of-c-sharp

0.0 3.0 0.0 99 KB

A curated collection of useful C# snippets that you can understand in 30 seconds or less.

License: MIT License

C# 100.00%

30-seconds-of-c-sharp's Introduction

Logo

CI Status License PRs Welcome

30 seconds of C#

A curated collection of useful C# snippets that you can understand in 30 seconds or less.

Note: This project is inspired by 30 Seconds of Code, but there is no affiliation with that project.

Table of Contents

⏱️ Date

View contents

📚 Enumerable

View contents

➗ Math

View contents

🎛️ Method

View contents

📜 String

View contents

📃️ Type

View contents

🔧 Utility

View contents

⏱️ Date

dayOfYear

Returns the day of the current year

Already integrated into C# https://docs.microsoft.com/de-de/dotnet/api/system.datetime.dayofyear?view=netframework-4.7.2

using System;

namespace Conplement.Snippets.Date
{
    public static partial class Date
    {
        public static int DayOfYear()
        {
            return DateTime.Now.DayOfYear;
        }
    }
}
Examples
Conplement.Snippets.Date.DayOfYear() # 12/31/2016: day 366 of 2016 (Leap Year)


↑ Back to top

formatDuration

Returns the human readable format of the given number of milliseconds.

// TODO
Examples
// TODO


↑ Back to top

getColonTimeFromDate

Returns a string of the form HH:MM:SS from a DateTime or TimeSpan object.

namespace Conplement.Snippets.Date
{
    public static partial class Date
    {
        public static string GetColonTimeFromDate(this DateTime dateTime)
        {
            return $"{dateTime.Hour.ToString("D2")}:{dateTime.Minute.ToString("D2")}:{dateTime.Second.ToString("D2")}";
        }

        public static string GetColonTimeFromDate(this TimeSpan timeSpan)
        {
            return $"{timeSpan.Hours.ToString("D2")}:{timeSpan.Minutes.ToString("D2")}:{timeSpan.Seconds.ToString("D2")}";
        }
    }
}
Examples
new DateTime(2018, 11, 22, 17, 53, 23).GetColonTimeFromDate() # 17:53:23
new DateTime(1990, 1, 2, 3, 41, 5).GetColonTimeFromDate() # 03:41:05
new TimeSpan(1, 33, 7).GetColonTimeFromDate() # 01:33:07


↑ Back to top

getDaysDiffBetweenDates

Returns the difference (in days) between two dates.

// TODO
Examples
// TODO


↑ Back to top

getMeridiumSuffixOfInteger

Converts an integer to a suffixed string, adding am or pm based on its value.

// TODO
Examples
// TODO


↑ Back to top

isAfterDate

Check if a date is after another date.

// TODO
Examples
// TODO


↑ Back to top

isBeforeDate

Check if a date is before another date.

// TODO
Examples
// TODO


↑ Back to top

isSameDate

Check if a date is the same as another date.

// TODO
Examples
// TODO


↑ Back to top

maxDate

Returns the maximum of the given dates.

// TODO
Examples
// TODO


↑ Back to top

minDate

Returns the minimum of the given dates.

// TODO
Examples
// TODO


↑ Back to top

tomorrow

Returns tomorrow's date.

// TODO
Examples
// TODO


↑ Back to top


📚 Enumerable

allEqual

Check if all elements in an array are equal.

// TODO
Examples
// TODO


↑ Back to top

arrayToCsv

Converts a 2D array to a comma-separated values (CSV) string.

// TODO
Examples
// TODO


↑ Back to top

bifurcate

Splits values into two groups. If an element in filter is truthy, the corresponding element in the collection belongs to the first group; otherwise, it belongs to the second group.

// TODO
Examples
// TODO


↑ Back to top

bubbleSort

bubbleSort uses the technique of comparing and swapping

// TODO
Examples
// TODO


↑ Back to top

chunk

Chunks an array into smaller arrays of a specified size.

// TODO
Examples
// TODO


↑ Back to top

compact

Removes invalid values from an array.

// TODO
Examples
// TODO


↑ Back to top

countBy

Groups the elements of an array based on the given function and returns the count of elements in each group.

// TODO
Examples
// TODO


↑ Back to top

countOccurrences

Counts the occurrences of a value in an array.

// TODO
Examples
// TODO


↑ Back to top

deepFlatten

Deep flattens an array of arrays.

// TODO
Examples
// TODO


↑ Back to top

difference

Returns the difference between two arrays.

// TODO
Examples
// TODO


↑ Back to top

differenceBy

Returns the difference between two arrays, after applying the provided function to each array element of both.

// TODO
Examples
// TODO


↑ Back to top

differenceWith

Filters out all values from an array for which the comparator function does not return true.

// TODO
Examples
// TODO


↑ Back to top

drop

Returns a new array with n elements removed from the left.

// TODO
Examples
// TODO


↑ Back to top

dropRight

Returns a new array with n elements removed from the right.

// TODO
Examples
// TODO


↑ Back to top

dropRightWhile

Removes elements from the end of an array until the passed function returns true. Returns the remaining elements in the array.

// TODO
Examples
// TODO


↑ Back to top

dropWhile

Removes elements in an array until the passed function returns true. Returns the remaining elements in the array.

namespace Conplement.Snippets.Enumerable
{
    public static partial class Enumerable
    {
        public static IEnumerable<T> DropWhile<T>(this IEnumerable<T> list, Func<T, bool> filter)
        {
            if (list == null)
            {
                throw new ArgumentNullException(nameof(list));
            }

            if (filter == null)
            {
                throw new ArgumentNullException(nameof(filter));
            }

            var reachedDropPoint = false;

            foreach (var element in list)
            {
                if (!reachedDropPoint && !filter(element))
                {
                    continue;
                }

                reachedDropPoint = true;

                yield return element;
            }

            yield break;
        }
    }
}
Examples
new List<int>{ 1, 2, 3, 4, 1}.DropWhile(x => x => x > 2); # new List<int> { 3, 4, 1 }


↑ Back to top

everyNth

Returns every nth element in an array.

// TODO
Examples
// TODO


↑ Back to top

filterNonUnique

Filters out the non-unique values in an array.

// TODO
Examples
// TODO


↑ Back to top

filterNonUniqueBy

Filters out the non-unique values in an array, based on a provided comparator function.

// TODO
Examples
// TODO


↑ Back to top

findLast

Returns the last element for which the provided function returns a truthy value.

// TODO
Examples
// TODO


↑ Back to top

findLastIndex

Returns the index of the last element for which the provided function returns a truthy value.

// TODO
Examples
// TODO


↑ Back to top

flatten

Flattens an array up to the specified depth.

// TODO
Examples
// TODO


↑ Back to top

forEachRight

Executes a provided function once for each array element, starting from the array's last element.

// TODO
Examples
// TODO


↑ Back to top

groupBy

Groups the elements of an array based on the given function.

// TODO
Examples
// TODO


↑ Back to top

hasDuplicates

Checks an array for duplicate values. Returns true if duplicate values exist and false if values are all unique.

// TODO
Examples
// TODO


↑ Back to top

head

Returns the head of a list.

// TODO
Examples
// TODO


↑ Back to top

indexOfAll

Returns all indices of a value in an array. If the value never occurs, returns [].

// TODO
Examples
// TODO


↑ Back to top

initial

Returns all the elements of an array except the last one.

// TODO
Examples
// TODO


↑ Back to top

initialize2DArray

Initializes a 2D array of given width and height and value.

namespace Conplement.Snippets.Enumerable
{
    public static partial class Enumerable
    {
        public static T[,] Initialize2DArray<T>(uint width, uint height, T defaultValue = default(T))
        {
            if (width == 0)
            {
                throw new ArgumentException($"Minimum {nameof(width)} has to be 1", nameof(width));
            }

            if (height == 0)
            {
                throw new ArgumentException($"Minimum {nameof(height)} has to be 1", nameof(height));
            }

            var newArray = new T[width, height];

            for (int widthIndex = 0; widthIndex < width; widthIndex++)
            {
                for (int heightIndex = 0; heightIndex < height; heightIndex++)
                {
                    newArray[widthIndex, heightIndex] = defaultValue;
                }
            }

            return newArray;
        }
    }
}
Examples
Enumerable.Initialize2DArray(2, 2, 0) # new int[2, 2] { { 0, 0 }, { 0, 0 } }


↑ Back to top

initializeArrayWithRange

Initializes an array containing the numbers in the specified range where start and end are inclusive with their common difference step.

// TODO
Examples
// TODO


↑ Back to top

initializeArrayWithRangeRight

Initializes an array containing the numbers in the specified range (in reverse) where start and end are inclusive with their common difference step.

// TODO
Examples
// TODO


↑ Back to top

initializeArrayWithValues

Initializes and fills an array with the specified values.

// TODO
Examples
// TODO


↑ Back to top

initializeNDArray

Create a n-dimensional array with given value.

// TODO
Examples
// TODO


↑ Back to top

intersection

Returns a list of elements that exist in both arrays.

// TODO
Examples
// TODO


↑ Back to top

intersectionBy

Returns a list of elements that exist in both arrays, after applying the provided function to each array element of both.

// TODO
Examples
// TODO


↑ Back to top

intersectionWith

Returns a list of elements that exist in both arrays, using a provided comparator function.

// TODO
Examples
// TODO


↑ Back to top

isSorted

Returns 1 if the array is sorted in ascending order, -1 if it is sorted in descending order or 0 if it is not sorted.

// TODO
Examples
// TODO


↑ Back to top

join

Joins all elements of an array into a string and returns this string. Uses a separator and an end separator.

// TODO
Examples
// TODO


↑ Back to top

jsonToCsv advanced

Converts an array of objects to a comma-separated values (CSV) string that contains only the columns specified.

// TODO
Examples
// TODO


↑ Back to top

last

Returns the last element in an array.

// TODO
Examples
// TODO


↑ Back to top

longestItem

Takes any number of iterable objects or objects with a length property and returns the longest one. If multiple objects have the same length, the first one will be returned. Returns -1 if no arguments are provided.

// TODO
Examples
// TODO


↑ Back to top

maxN

Returns the n maximum elements from the provided array. If n is greater than or equal to the provided array's length, then return the original array (sorted in descending order).

// TODO
Examples
// TODO


↑ Back to top

minN

Returns the n minimum elements from the provided array. If n is greater than or equal to the provided array's length, then return the original array (sorted in ascending order).

// TODO
Examples
// TODO


↑ Back to top

none

Returns true if the provided predicate function returns false for all elements in a collection, false otherwise.

// TODO
Examples
// TODO


↑ Back to top

nthElement

Returns the nth element of an array.

// TODO
Examples
// TODO


↑ Back to top

offset

Moves the specified amount of elements to the end of the array.

// TODO
Examples
// TODO


↑ Back to top

orderBy

Sorts a collection of arrays.

// TODO
Examples
// TODO


↑ Back to top

partition

Groups the elements into two arrays, depending on the provided function's truthiness for each element.

// TODO
Examples
// TODO


↑ Back to top

permutations advanced

⚠️ WARNING: This function's execution time increases exponentially with each array element.

Generates all permutations of an array's elements (contains duplicates).

// TODO
Examples
// TODO


↑ Back to top

pluck

Retrieves all of the values for a given key.

// TODO
Examples
// TODO


↑ Back to top

pull

Mutates the original array to filter out the values specified.

// TODO
Examples
// TODO


↑ Back to top

pullAtIndex advanced

Mutates the original array to filter out the values at the specified indexes.

// TODO
Examples
// TODO


↑ Back to top

pullAtValue advanced

Mutates the original array to filter out the values specified. Returns the removed elements.

// TODO
Examples
// TODO


↑ Back to top

pullBy advanced

Mutates the original array to filter out the values specified, based on a given iterator function.

// TODO
Examples
// TODO


↑ Back to top

reduceFilter

Filter an array of objects based on a condition while also filtering out unspecified keys.

// TODO
Examples
// TODO


↑ Back to top

reduceSuccessive

Applies a function against an accumulator and each element in the array (from left to right), returning an array of successively reduced values.

// TODO
Examples
// TODO


↑ Back to top

reduceWhich

Returns the minimum/maximum value of an array, after applying the provided function to set comparing rule.

// TODO
Examples
// TODO


↑ Back to top

reject

Takes a predicate and array, like Array.prototype.filter(), but only keeps x if pred(x) === false.

// TODO
Examples
// TODO


↑ Back to top

remove

Removes elements from an array for which the given function returns false.

// TODO
Examples
// TODO


↑ Back to top

sample

Returns a random element from an array.

// TODO
Examples
// TODO


↑ Back to top

sampleSize

Gets n random elements at unique keys from array up to the size of array.

// TODO
Examples
// TODO


↑ Back to top

shank

This method changes the contents of an array by removing existing elements and/or adding new elements. Similar to the JavaScript version Array.prototype.splice()

// TODO
Examples
// TODO


↑ Back to top

shuffle

Randomizes the order of the values of an array, returning a new array.

// TODO
Examples
// TODO


↑ Back to top

similarity

Returns an array of elements that appear in both arrays.

// TODO
Examples
// TODO


↑ Back to top

sortedIndex

Returns the lowest index at which value should be inserted into array in order to maintain its sort order.

// TODO
Examples
// TODO


↑ Back to top

sortedIndexBy

Returns the lowest index at which value should be inserted into array in order to maintain its sort order, based on a provided iterator function.

// TODO
Examples
// TODO


↑ Back to top

sortedLastIndex

Returns the highest index at which value should be inserted into array in order to maintain its sort order.

// TODO
Examples
// TODO


↑ Back to top

sortedLastIndexBy

Returns the highest index at which value should be inserted into array in order to maintain its sort order, based on a provided iterator function.

// TODO
Examples
// TODO


↑ Back to top

stableSort advanced

Performs stable sorting of an array, preserving the initial indexes of items when their values are the same. Does not mutate the original array, but returns a new array instead.

// TODO
Examples
// TODO


↑ Back to top

symmetricDifference

Returns the symmetric difference between two arrays, without filtering out duplicate values.

// TODO
Examples
// TODO


↑ Back to top

symmetricDifferenceBy

Returns the symmetric difference between two arrays, after applying the provided function to each array element of both.

// TODO
Examples
// TODO


↑ Back to top

symmetricDifferenceWith

Returns the symmetric difference between two arrays, using a provided function as a comparator.

// TODO
Examples
// TODO


↑ Back to top

tail

Returns all elements in an array except for the first one.

// TODO
Examples
// TODO


↑ Back to top

take

Returns an array with n elements removed from the beginning.

// TODO
Examples
// TODO


↑ Back to top

takeRight

Returns an array with n elements removed from the end.

// TODO
Examples
// TODO


↑ Back to top

takeRightWhile

Removes elements from the end of an array until the passed function returns true. Returns the removed elements.

// TODO
Examples
// TODO


↑ Back to top

takeWhile

Removes elements in an array until the passed function returns true. Returns the removed elements.

// TODO
Examples
// TODO


↑ Back to top

toHash

Reduces a given Array-like into a value hash (keyed data store).

// TODO
Examples
// TODO


↑ Back to top

union

Returns every element that exists in any of the two arrays once.

// TODO
Examples
// TODO


↑ Back to top

unionBy

Returns every element that exists in any of the two arrays once, after applying the provided function to each array element of both.

// TODO
Examples
// TODO


↑ Back to top

unionWith

Returns every element that exists in any of the two arrays once, using a provided comparator function.

// TODO
Examples
// TODO


↑ Back to top

uniqueElements

Returns all unique values of an array.

// TODO
Examples
// TODO


↑ Back to top

uniqueElementsBy

Returns all unique values of an array, based on a provided comparator function.

// TODO
Examples
// TODO


↑ Back to top

uniqueElementsByRight

Returns all unique values of an array, based on a provided comparator function.

// TODO
Examples
// TODO


↑ Back to top

uniqueSymmetricDifference

Returns the unique symmetric difference between two arrays, not containing duplicate values from either array.

// TODO
Examples
// TODO


↑ Back to top

without

Filters out the elements of an array, that have one of the specified values.

// TODO
Examples
// TODO


↑ Back to top

xProd

Creates a new array out of the two supplied by creating each possible pair from the arrays.

// TODO
Examples
// TODO


↑ Back to top


➗ Math

approximatelyEqual

Checks if two numbers are approximately equal to each other.

// TODO
Examples
// TODO


↑ Back to top

average

Returns the average of two or more numbers.

The method excepts numbers as params and returns the average as a result

Linq documentation https://docs.microsoft.com/en-us/dotnet/api/system.linq.enumerable.sum?view=netframework-4.7.2

namespace Conplement.Snippets.Math
{
    public static partial class Math
    {
        public static double Average(this uint[] elements)
        {
            if (elements.Length == 0) return 0;
            return elements.Aggregate(0.0, (current, element) => current + element) / elements.Length;
        }
    }
}
Examples
{ 4, 5, 9, 1, 0 }.Average() # 3.8


↑ Back to top

averageBy

Returns the average of an array, after mapping each element to a value using the provided function.

// TODO
Examples
// TODO


↑ Back to top

binomialCoefficient

Evaluates the binomial coefficient of two integers n and k.

// TODO
Examples
// TODO


↑ Back to top

degreesToRads

Converts an angle from degrees to radians.

// TODO
Examples
// TODO


↑ Back to top

digitize

Converts a number to an array of digits.

// TODO
Examples
// TODO


↑ Back to top

distance

Returns the distance between two points.

// TODO
Examples
// TODO


↑ Back to top

factorial

Calculates the factorial of a number.

// TODO
Examples
// TODO


↑ Back to top

fibonacci

Generates an array, containing the Fibonacci sequence, up until the nth term.

// TODO
Examples
// TODO


↑ Back to top

gcd

Calculates the greatest common divisor between two or more numbers/arrays.

// TODO
Examples
// TODO


↑ Back to top

geometricProgression

Initializes an array containing the numbers in the specified range where start and end are inclusive and the ratio between two terms is step. Returns an error if step equals 1.

// TODO
Examples
// TODO


↑ Back to top

inRange

Checks if the given number falls within the given range.

// TODO
Examples
// TODO


↑ Back to top

isDivisible

Checks if the first numeric argument is divisible by the second one.

// TODO
Examples
// TODO


↑ Back to top

isEven

Returns true if the given number is even, false otherwise.

// TODO
Examples
// TODO


↑ Back to top

isPrime

Checks if the provided integer is a prime number.

// TODO
Examples
// TODO


↑ Back to top

isOdd

Returns true if the given number is odd, false otherwise.

// TODO
Examples
// TODO


↑ Back to top

lcm

Returns the least common multiple of two or more numbers.

// TODO
Examples
// TODO


↑ Back to top

luhnCheck advanced

Implementation of the Luhn Algorithm used to validate a variety of identification numbers, such as credit card numbers, IMEI numbers, National Provider Identifier numbers etc.

// TODO
Examples
// TODO


↑ Back to top

max

Returns the maximum value from the provided enumerable.

// TODO
Examples
// TODO


↑ Back to top

median

Returns the median of an array of numbers.

// TODO
Examples
// TODO


↑ Back to top

min

Returns the minimum value from the provided enumerable.

// TODO
Examples
// TODO


↑ Back to top

primes

Generates primes up to a given number, using the Sieve of Eratosthenes.

// TODO
Examples
// TODO


↑ Back to top

radsToDegrees

Converts an angle from radians to degrees.

// TODO
Examples
// TODO


↑ Back to top

randomIntArrayInRange

Returns an array of n random integers in the specified range.

// TODO
Examples
// TODO


↑ Back to top

randomIntegerInRange

Returns a random integer in the specified range.

// TODO
Examples
// TODO


↑ Back to top

randomNumberInRange

Returns a random number in the specified range.

// TODO
Examples
// TODO


↑ Back to top

round

Rounds a number to a specified amount of digits.

// TODO
Examples
// TODO


↑ Back to top

sdbm

Hashes the input string into a whole number.

// TODO
Examples
// TODO


↑ Back to top

standardDeviation

Returns the standard deviation of an array of numbers.

// TODO
Examples
// TODO


↑ Back to top

sum

Returns the sum of two or more numbers/arrays.

// TODO
Examples
// TODO


↑ Back to top

sumBy

Returns the sum of an array, after mapping each element to a value using the provided function.

// TODO
Examples
// TODO


↑ Back to top


🎛️ Method

hz

Returns the number of times a function executed per second. hz is the unit for hertz, the unit of frequency defined as one cycle per second.

// TODO
Examples
// TODO


↑ Back to top

times

Iterates over a callback n times

namespace Conplement.Snippets.Method
{
    public static partial class Method
    {
        public static IList<T1> Times<T1>(Func<T1> func, uint times)
        {
            var list = new List<T1>();

            for (var index = 0; index < times; index++)
            {
                list.Add(func());
            }

            return list;
        }
    }
}
Examples
Method.Times((() => true), 3) # list of size 3, all values true
Method.Times(((int start, int end) => new Random().Next(start, end)), 6, 0, 100) # list of size 6 with 6 random integers between 0 and 100


↑ Back to top


📜 String

byteSize

Returns the length of a string in bytes.

// TODO
Examples
// TODO


↑ Back to top

capitalize

Capitalizes the first letter of a string.

// TODO
Examples
// TODO


↑ Back to top

capitalizeEveryWord

Capitalizes the first letter of every word in a string.

// TODO
Examples
// TODO


↑ Back to top

countVowels

Returns number of vowels in provided string.

// TODO
Examples
// TODO


↑ Back to top

csvToArray

Converts a comma-separated values (CSV) string to a 2D array.

// TODO
Examples
// TODO


↑ Back to top

csvToJson advanced

Converts a comma-separated values (CSV) string to a 2D array of objects. The first row of the string is used as the title row.

// TODO
Examples
// TODO


↑ Back to top

decapitalize

Decapitalizes the first letter of a string.

// TODO
Examples
// TODO


↑ Back to top

endsWithRegex

Check if a string is ends with a given substring using a regex

The method excepts the string to test and a regex

Most other checks are already integrated into C# https://docs.microsoft.com/en-us/dotnet/api/system.string.endswith?view=netframework-4.7.2

namespace Conplement.Snippets.String
{
    public static partial class String
    {
        public static bool EndsWithRegex(this string input, Regex regex)
        {
            return regex.IsMatch(input);
        }
    }
}
Examples
"Hello World".EndsWithRegex(new Regex(@"[dolrwDOLRW]{5}$")) # true


↑ Back to top

escapeHtml

Escapes a string for use in HTML.

// TODO
Examples
// TODO


↑ Back to top

escapeRegExp

Escapes a string to use in a regular expression.

// TODO
Examples
// TODO


↑ Back to top

fromCamelCase

Converts a string from camelcase.

// TODO
Examples
// TODO


↑ Back to top

indentString

Indents each line in the provided string.

// TODO
Examples
// TODO


↑ Back to top

isAbsoluteUrl

Returns true if the given string is an absolute URL, false otherwise.

// TODO
Examples
// TODO


↑ Back to top

isAnagram

Checks if a string is an anagram of another string (case-insensitive, ignores spaces, punctuation and special characters).

// TODO
Examples
// TODO


↑ Back to top

isLowerCase

Checks if a string is lower case.

// TODO
Examples
// TODO


↑ Back to top

isUpperCase

Checks if a string is upper case.

// TODO
Examples
// TODO


↑ Back to top

mask

Replaces all but the last num of characters with the specified mask character.

// TODO
Examples
// TODO


↑ Back to top

pad

Pads a string on both sides with the specified character, if it's shorter than the specified length.

// TODO
Examples
// TODO


↑ Back to top

palindrome

Returns true if the given string is a palindrome, false otherwise.

// TODO
Examples
// TODO


↑ Back to top

pluralize

Returns the singular or plural form of the word based on the input number. If the first argument is an object, it will use a closure by returning a function that can auto-pluralize words that don't simply end in s if the supplied dictionary contains the word.

// TODO
Examples
// TODO


↑ Back to top

removeNonAscii

Removes non-printable ASCII characters.

// TODO
Examples
// TODO


↑ Back to top

reverseString

Reverses a string.

// TODO
Examples
// TODO


↑ Back to top

sortCharactersInString

Alphabetically sorts the characters in a string.

// TODO
Examples
// TODO


↑ Back to top

splitLines

Splits a multiline string into an array of lines.

// TODO
Examples
// TODO


↑ Back to top

startsWithRegex

Check if a string starts with a given regex.

// TODO
Examples
// TODO


↑ Back to top

stringPermutations advanced

⚠️ WARNING: This function's execution time increases exponentially with each character.

Generates all permutations of a string (contains duplicates).

// TODO
Examples
// TODO


↑ Back to top

stripHtmlTags

Removes HTML/XML tags from string.

// TODO
Examples
// TODO


↑ Back to top

toCamelCase

Converts a string to camelcase.

// TODO
Examples
// TODO


↑ Back to top

toKebabCase

Converts a string to kebab case.

// TODO
Examples
// TODO


↑ Back to top

toSnakeCase

Converts a string to snake case.

// TODO
Examples
// TODO


↑ Back to top

toTitleCase

Converts a string to title case.

// TODO
Examples
// TODO


↑ Back to top

truncateString

Truncates a string up to a specified length.

// TODO
Examples
// TODO


↑ Back to top

unescapeHTML

Unescapes escaped HTML characters.

// TODO
Examples
// TODO


↑ Back to top

urlJoin advanced

Joins all given URL segments together, then normalizes the resulting URL

// TODO
Examples
// TODO


↑ Back to top

words

Converts a given string into an array of words.

// TODO
Examples
// TODO


↑ Back to top


📃️ Type

is

Checks if the provided value is of the specified type.

// TODO
Examples
// TODO


↑ Back to top

isValidJson

Checks if the provided argument is a valid JSON.

// TODO
Examples
// TODO


↑ Back to top


🔧 Utility

coalesce

Returns the first non-null argument.

// TODO
Examples
// TODO


↑ Back to top

extendHex

Extends a 3-digit color code to a 6-digit color code.

// TODO
Examples
// TODO


↑ Back to top

getUrlParameters

Returns an object containing the parameters of the current URL.

// TODO
Examples
// TODO


↑ Back to top

hexToRgb advanced

Converts a color code to a rgb() or rgba() string if alpha value is provided.

// TODO
Examples
// TODO


↑ Back to top

mostPerformant

Returns the index of the function in an array of functions which executed the fastest.

// TODO
Examples
// TODO


↑ Back to top

prettyBytes advanced

Converts a number in bytes to a human-readable string.

// TODO
Examples
// TODO


↑ Back to top

randomHexColorCode

Generates a random hexadecimal color code.

// TODO
Examples
// TODO


↑ Back to top

rgbToHex

Converts the values of RGB components to a color code.

// TODO
Examples
// TODO


↑ Back to top

timeTaken

Measures the time taken by a function to execute.

Stopwatch documentation https://docs.microsoft.com/en-us/dotnet/api/system.diagnostics.stopwatch?redirectedfrom=MSDN&view=netframework-4.7.2

namespace Conplement.Snippets.Utility
{
    public static partial class Utility
    {
        public static (long, T1) TimeTaken<T1>(Func<T1> func)
        {
            var watch = Stopwatch.StartNew();
            T1 result = func.Invoke();
            watch.Stop();
            return (watch.ElapsedMilliseconds, result);
        }
    }
}
Examples
Utility.TimeTaken(() => true) # 13.37ms, true


↑ Back to top

toOrdinalSuffix

Adds an ordinal suffix to a number.

// TODO
Examples
// TODO


↑ Back to top

yesNo

Returns true if the string is y/yes or false if the string is n/no.

// TODO
Examples
// TODO


↑ Back to top

Contribute

You're always welcome to contribute to this project. Please read the contribution guide.

License

This project is licensed under the MIT License - see the License File for details

30-seconds-of-c-sharp's People

Contributors

denisbiondic avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.