C# Programming Insights

Latest From Blog

Search An Array If It Contains The Keyword Image

Search An Array If It Contains The Keyword

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 article
Check If The Text Contains A Keyword From The Array Image

Check If The Text Contains A Keyword From The Array

LINQ Any provides a quick and compact syntax for checking if the text contains a keyword from a string array.

Read more in article
Best Initializer To Get An Empty Array Image

Best Initializer To Get An Empty Array

The 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 article
How To Initialize Arrays Image

How To Initialize Arrays

There are 4 main ways to initialize an array. One initializes to null or default, array initializers, shorthand and new operator.

Read more in article
How To Encode Strings and Decode Byte Arrays Image

How To Encode Strings and Decode Byte Arrays

A 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 article
How To Assign Values to An Array Image

How To Assign Values to An Array

The 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 article
Introduction To Array Image

Introduction To Array

Arrays are a fundamental data structure in programming. C# provides a fast, simple and generic array implementation

Read more in article
Dictionary With One To Many Relationship Image

Dictionary With One To Many Relationship

There 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 article
TryGetValue Vs ContainsKey With Indexer Image

TryGetValue Vs ContainsKey With Indexer

TryGetValue 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 article
Fix For Collection Was Modified And Enumeration Not Executed Image

Fix For Collection Was Modified And Enumeration Not Executed

A Fix For Collection Was Modified And Enumeration Not Executed comes by copying parts or the whole dictionary in the reader thread.

Read more in article
Get A List Of Dictionary Keys Image

Get A List Of Dictionary Keys

To 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 article
Declare A New Dictionary in Function Calls Image

Declare A New Dictionary in Function Calls

There 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 article
Make A Dictionary Key Case Insensitive Image

Make A Dictionary Key Case Insensitive

To make a dictionary case insensitive it must be done in the declaration. There are three options and OrdinalIgnoreCase is the fastest.

Read more in article
How To Change A Dictionary Key Image

How To Change A Dictionary Key

Changing 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 article
Two Lists of Keys and Values Mapped To a Dictionary Image

Two Lists of Keys and Values Mapped To a Dictionary

Mapping 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 article
Convert A List Into a Dictionary Image

Convert A List Into a Dictionary

The 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 article
Best Merging Method For Two Dictionaries Image

Best Merging Method For Two Dictionaries

The best dictionary merge method is the merge loop method. You can write yourself and it faster than the LINQ methods

Read more in article
Get Dictionary Element By Index Image

Get Dictionary Element By Index

ElemenatAt lets a dictionary be accessed by numeric values, but this is far not the best way.

Read more in article
How To Initialize A Dictionary Image

How To Initialize A Dictionary

C# provides Collection Initializers syntax to initialize dictionaries to simple, quick and readable code.

Read more in article
Dictionary Vs Hashtable Comparison Image

Dictionary Vs Hashtable Comparison

Dictionary performs much better than Hashtable. It is a clear example why it is better to use a generic collection type

Read more in article
Check If The Key Exists In The Dictionary Image

Check If The Key Exists In The Dictionary

TryGetValue is best suited for the check if the key exists in the dictionary because it checks then returns the value too.

Read more in article
Best Sort Method for Dictionary Values Image

Best Sort Method for Dictionary Values

Using a LINQ Extension method is the best way to sort a dictionary by value. It is quick and easy to implement

Read more in article
How To Update Dictionary Values Image

How To Update Dictionary Values

TryGetValue 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 article
Get The Dictionary Keys By Their Value Image

Get The Dictionary Keys By Their Value

The 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 article
Best Way To Iterate Through A Dictionary Image

Best Way To Iterate Through A Dictionary

Dictionary 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 article
A Comparison Between IEnumerable<T> and List<T> Image

A Comparison Between IEnumerable<T> and List<T>

When comparing List to IEnumerable, List has more functionality but using LINQ with IEnumerable it has better performance than List.

Read more in article
 Convert A System Array To A List Image

Convert A System Array To A List

The 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 article
Understanding The Best Set Theory Methods Between Lists Image

Understanding The Best Set Theory Methods Between Lists

The best methods for intersect, union and except are with the HashSet collection type. The HashSet functions are faster than LINQs.

Read more in article
Remove Duplicate Items from A List Image

Remove Duplicate Items from A List

The 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 article
Clone A List In Depth Review Image

Clone A List In Depth Review

Cloning a list is matter of understanding the differences in shallow, deep copies and the difference between value and reference types.

Read more in article
Introduction To Dictionary Image

Introduction To Dictionary

Dictionary are fundamental type in C#. They provide fast lookup to for values found in the dictionary.

Read more in article
Introduction To List Image

Introduction To List

List 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 article
Collections Image

Collections

Collections 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 article
Strings Image

Strings

Strings 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 article
Code Snippets Image

Code Snippets

Code 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 article
How To Find An Item In The List Image

How To Find An Item In The List

The 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 article
Convert A List To String With A Delimiter Image

Convert A List To String With A Delimiter

The 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 article
How To Initialize A List Image

How To Initialize A List

Initializing 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 article
Best Way To Sort A List Image

Best Way To Sort A List

The best sorting method in C# is LINQ's order by function. It is the fastest method and it is compact.

Read more in article
Access Items From A List By Index Image

Access Items From A List By Index

The 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 article
Get A Substring Between Two Strings Image

Get A Substring Between Two Strings

The 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 article
Analysis Of Getting First N Characters Methods Image

Analysis Of Getting First N Characters Methods

The 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 article
How Best To Get Last N Characters Image

How Best To Get Last N Characters

Best 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 article
Get Substring After Finding A Keyword Image

Get Substring After Finding A Keyword

The 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 article
Best First Character Removal Function In A String Image

Best First Character Removal Function In A String

Span 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 article
Efficiently Remove The First Keyword Occurrence From A String Image

Efficiently Remove The First Keyword Occurrence From A String

Data 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 article
Get A Substring Before Or After A Certain Character Image

Get A Substring Before Or After A Certain Character

Getting 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 article
Examining String Equals In Detail Image

Examining String Equals In Detail

String 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 article
String Replace In Depth Image

String Replace In Depth

String 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 article
Walkthrough of the String Trim Function Image

Walkthrough of the String Trim Function

String 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 article
Using String Insert Effectively Image

Using String Insert Effectively

String 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 article
Best Ways To Use String Remove Image

Best Ways To Use String Remove

String 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 article
How to Use Substring Image

How to Use Substring

Substring 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 article
Array vs List vs Linked List Image

Array vs List vs Linked List

Array 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 article
Fix For Default Parameter Value Not Compile Time Constant Error Image

Fix For Default Parameter Value Not Compile Time Constant Error

The 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 article
Dictionary Best Practices And What To Avoid Image

Dictionary Best Practices And What To Avoid

Dictionary using best practices with the right key, it scales well over large datasets. There are several pitfalls that should be avoided.

Read more in article
Copying Files via Project Script On Build Image

Copying Files via Project Script On Build

One 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 article
List vs Dictionary Collection Types Image

List vs Dictionary Collection Types

List 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 article
Identify If a DLL is 32bit or 64bit Image

Identify If a DLL is 32bit or 64bit

Want 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 article
Hex String to Int Image

Hex String to Int

Hex 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 article
String vs StringBuilder Comparison Image

String vs StringBuilder Comparison

String vs StringBuilder are similar and in most cases we will use string but we need a more efficient option in StringBuilder.

Read more in article
Open File Programmatically Image

Open File Programmatically

When testing or writing programs that generate files you may want automate opening the file in code than manually opening those files.

Read more in article
New Line in StringBuilder Image

New Line in StringBuilder

New 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 article

Welcome 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.