LINQ Contains provides the fastest method for searching an array for an element match. it is on one line but it is not as flexible as Array Exits.
Read more in articleLINQ Any provides a quick and compact syntax for checking if the text contains a keyword from a string array.
Read more in articleThe static array empty method is the best initializer for an empty array. It does what it says and quick to use by using one step.
Read more in articleThere are 4 main ways to initialize an array. One initializes to null or default, array initializers, shorthand and new operator.
Read more in articleA string can be converted to a byte array and visa versa. C# provides encoders classes that can do this operation by GetString and GetBytes.
Read more in articleThe Array Indexer is the best way assign values for the entire array. It's fast, less code and no need to convert between types.
Read more in articleArrays are a fundamental data structure in programming. C# provides a fast, simple and generic array implementation
Read more in articleThere are a couple ways to have a one to many collection type. You can use dictionary with List or List of KeyValuePairs. Each with pros and cons.
Read more in articleTryGetValue is the best method for getting values from a dictionary. It performances better and has takes up less code than using ContainsKey with Indexer.
Read more in articleA Fix For Collection Was Modified And Enumeration Not Executed comes by copying parts or the whole dictionary in the reader thread.
Read more in articleTo get a list from the dictionary's keys, LINQ's ToList is concise and easy to read and just as fast as the list constructor.
Read more in articleThere are small differences in creating dictionary in a function, but the Index Initializer has the best performance and easiest to read syntax
Read more in articleTo make a dictionary case insensitive it must be done in the declaration. There are three options and OrdinalIgnoreCase is the fastest.
Read more in articleChanging the dictionary key is only possible by removing the existing key and adding the new key and existing value. This has the best performance.
Read more in articleMapping two lists to a dictionary is best down manually. It has the best performance and also can handle duplicate keys without thrown exceptions
Read more in articleThe best way to convert a list to dictionary is to use the dictionary indexer. It is fast enough,has simple syntax and works with duplicates.
Read more in articleThe best dictionary merge method is the merge loop method. You can write yourself and it faster than the LINQ methods
Read more in articleElemenatAt lets a dictionary be accessed by numeric values, but this is far not the best way.
Read more in articleC# provides Collection Initializers syntax to initialize dictionaries to simple, quick and readable code.
Read more in articleDictionary performs much better than Hashtable. It is a clear example why it is better to use a generic collection type
Read more in articleTryGetValue is best suited for the check if the key exists in the dictionary because it checks then returns the value too.
Read more in articleUsing a LINQ Extension method is the best way to sort a dictionary by value. It is quick and easy to implement
Read more in articleTryGetValue is the best method for updating a value because it checks if the key exists and retrieves and returns the value to use right away.
Read more in articleThe best way to get keys by their value from a dictionary is to use the dictionary and list combo. This gives speed and flexibility.
Read more in articleDictionary fastest methods are iterating over just the Keys and Values but looping through both Key and Value a list with a class container performs better
Read more in articleWhen comparing List to IEnumerable, List has more functionality but using LINQ with IEnumerable it has better performance than List.
Read more in articleThe fastest method for converting a system array to a list is to use a array cast then use ToList. It is short and compact and easy to read.
Read more in articleThe best methods for intersect, union and except are with the HashSet collection type. The HashSet functions are faster than LINQs.
Read more in articleThe best method for getting unique items from a list is to use a combination of HashSet and List. It has good performance and the order the items is preserved.
Read more in articleCloning a list is matter of understanding the differences in shallow, deep copies and the difference between value and reference types.
Read more in articleDictionary are fundamental type in C#. They provide fast lookup to for values found in the dictionary.
Read more in articleList are the backbone of collections and often the most used. They are versatile and flexible, they increase and decrease the underline array automatically.
Read more in articleCollections are an essential data type in csharp. It is one the most used types because data must be ordered, organized and then used in an efficient manner.
Read more in articleStrings are some of the first data types to learn in the csharp so it becomes important to manipulate strings, and to parsing strings
Read more in articleCode snippet is is sections of brief code and explanation that could be useful to you for simple yet fundamental issues that could arise.
Read more in articleThe best method for finding an item in a list is the List Find method, however, the best collection type for finding an item is the dictionary.
Read more in articleThe best method to convert a list to a string with a delimiter is the string join method. It is by far the fastest, it is compact and also easy to setup.
Read more in articleInitializing the list using the in line method is best used when there are only a few items and also where the list won't change much very often.
Read more in articleThe best sorting method in C# is LINQ's order by function. It is the fastest method and it is compact.
Read more in articleThe best way to access an item of a list is to use the Indexer property. It is extremely fast and once used to the syntax, it becomes a go to property
Read more in articleThe most effective function for getting a substring between two strings is span slice. Speed is important factor because that has the impacts on the end user.
Read more in articleThe best method for getting the first n characters is span slice. Performance is the best metric to determine to which is best because it affects the end users.
Read more in articleBest way to get last n characters is to use string substring. It has one of the fastest methods and readable so you don't have to guess what it does.
Read more in articleThe overall best way to solve getting a substring after finding a keyword is with Span Slice because of the huge performance gain.
Read more in articleSpan Slice came at the fastest first character removal method at about half a second while substring, range operator, remove, and trim start were pretty fast.
Read more in articleData can have duplicated and errors can be in the inputs and fields and it is important to efficiently removing the first keyword occurrence from a string
Read more in articleGetting a substring before or after a certain character is common in parsing strings, user data, database data, automatic data generated by scripts.
Read more in articleString Equals compares two string to find out if they are exactly the same. The compare is case sensitive and usually used in conditional statements.
Read more in articleString replace is a string and character substitute with another string. It finds the characters then replaces it a new set of characters
Read more in articleString trim removes space, tabs and various lengths of whitespace at the beginning or end of a string. This is good for user inputs.
Read more in articleString insert puts a single string between a section of the string. With the first parameter of index of insert and second parameter is the string to insert.
Read more in articleString remove takes an existing string and based on the start index and length for removal then will return a string with that section removed.
Read more in articleSubstring is a function for copying a chunk of an existing string. It returns a sub section of the original string and depends on the selected index range.
Read more in articleArray vs Lists vs Linked Lists are common collections, each pros and cons so it is important to understand these as we make our collection choices.
Read more in articleThe exception CS1736:Default parameter value must be a compile-time constant comes when assigning a optional parameter value is not a constant or default value.
Read more in articleDictionary using best practices with the right key, it scales well over large datasets. There are several pitfalls that should be avoided.
Read more in articleOne way to copy files to output folder is to edit the .csproj file and add a command copy files from a certain directory into the output folder.
Read more in articleList and Dictionary are useful collection types. They are accessibility and convenient to use. There are advantages over an array or hash tables.
Read more in articleWant to find out if a DLL or assembly is targeting 32bit or 64bit then Visual Studio comes with handy tool called Corflags accessed by the command prompt.
Read more in articleHex is a base 16 number system and the C# has build in function that can convert a string hex value into a int value.
Read more in articleString vs StringBuilder are similar and in most cases we will use string but we need a more efficient option in StringBuilder.
Read more in articleWhen testing or writing programs that generate files you may want automate opening the file in code than manually opening those files.
Read more in articleNew line is a special sequences that can be inserted into a string. Represented as backslash n this works as if you pressed return on the keyboard.
Read more in articleWelcome to my home page. This site was created for you to gain new insights into the C# programming language. There are a variety of how to articles, code snippets and practice code, which cover a variety of topics.