Welcome!

This site was created for you to gain new insights into the C# programming language. There are a variety of how-to articles, and code snippets. Search below to quickly browse the content.
Home Page Splash Video Looped

C# Programming Insights

Latest From Blog

C# Serialization By Transforming Objects into A JSON String Image

C# Serialization By Transforming Objects into A JSON String

C# has a fast and easy-to-implement object serialization into JSON with the help of JsonSerializer.

Read more in article
Why You Should Not Try To Modify A IEnumerable Collection Image

Why You Should Not Try To Modify A IEnumerable Collection

In C#, IEnumerable was not designed to be modified so it is best to use List when trying to modify a collection

Read more in article
How To Install Visual Studio Image

How To Install Visual Studio

This is a step-by-step guild to install Visual Studio. It is a great IDE to work with and has rich features and debugging tools.

Read more in article
The Best C# Deserializer To Convert JSON To An Object Image

The Best C# Deserializer To Convert JSON To An Object

In C#, JsonSerializer Deserialize is the best JSON Deserializer method as it is the fastest based on my testing. It has native C# support.

Read more in article
Copy Part Of An Array To Another Array In C# Image

Copy Part Of An Array To Another Array In C#

In C#, Array Copy is best to use when copying part of an array to another array. It fits on one line and it is fast. Also, it has no limitation on types.

Read more in article
How To Combine Two Arrays Into One In C# Image

How To Combine Two Arrays Into One In C#

The best method for combining two arrays into one in C# is Enumerable Concat. It is fast, easy to read, and fits on one line.

Read more in article
Solutions For Fill The Array With One Value In C# Image

Solutions For Fill The Array With One Value In C#

In C#, Enumerable Repeat is the fastest method to fill an array with one value. It is compact and readable a good combination.

Read more in article
Best Solution In .NET For Slicing Arrays Image

Best Solution In .NET For Slicing Arrays

The C# ArraySegment Method is the fastest for slicing an array, with many other good ones to choose from. With a short syntax and has a long framework support.

Read more in article
Best Removal Method In C# Of Duplicates From An Array Image

Best Removal Method In C# Of Duplicates From An Array

In C#, LINQ Distinct is the best method for removing duplicate items from an array. It is the fastest method,and really compact and readably.

Read more in article
Search An Array If It Contains The Keyword In C# Image

Search An Array If It Contains The Keyword In C#

In C#, 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
In C#, Check If The Text Contains A Keyword From The Array Image

In C#, Check If The Text Contains A Keyword From The Array

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

Read more in article
6 C# Initializers To Get An Empty Array In 2023  Image

6 C# Initializers To Get An Empty Array In 2023

In C#, 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 C# Arrays Image

How To Initialize C# Arrays

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

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

How To Encode C# Strings and Decode Byte Arrays

A C# 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 A C# Array Image

How To Assign Values To A C# Array

The Array Indexer is the best way in C# to 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 | Puzzled By C# Image

Introduction To Array | Puzzled By C#

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

Read more in article
C# Dictionary With One To Many Relationship Image

C# Dictionary With One To Many Relationship

There are a couple of ways to have a one-to-many collection type. You can use a dictionary in C# with a List or List of KeyValuePairs. Each with pros and cons.

Read more in article
TryGetValue Vs ContainsKey With Indexer In .NET Image

TryGetValue Vs ContainsKey With Indexer In .NET

TryGetValue is the best .NET method for getting values from a dictionary. It performs better and takes up less code than using ContainsKey with Indexer.

Read more in article
Fix For Collection Was Modified And Enumeration Not Executed In .NET Image

Fix For Collection Was Modified And Enumeration Not Executed In .NET

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 In C# Image

Get A List Of Dictionary Keys In C#

To get a list from the dictionary's keys, C# has 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 Using C# Image

Declare A New Dictionary in Function Calls Using C#

There are small differences in creating a C# dictionary in a function, but the Index Initializer has the best performance and easiest-to-read syntax.

Read more in article
Make A .NET Dictionary Key Case Insensitive Image

Make A .NET Dictionary Key Case Insensitive

In .NET, 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 In C# Image

How To Change A Dictionary Key In C#

Changing the C# 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 In C# Image

Two Lists of Keys and Values Mapped To a Dictionary In C#

Mapping two lists into a dictionary is best done manually. It has the best performance and also can handle duplicate keys without throwing exceptions.

Read more in article
Convert A List Into a Dictionary In C# Image

Convert A List Into a Dictionary In C#

The best way in C# to convert a list to a dictionary is to use the dictionary indexer. It is fast enough, has simple syntax, and works with duplicates.

Read more in article
Best C# Merging Method For Two Dictionaries Image

Best C# Merging Method For Two Dictionaries

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

Read more in article
Get C# Dictionary Element By Index Image

Get C# Dictionary Element By Index

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

Read more in article
How To Initialize A Dictionary In C# Image

How To Initialize A Dictionary In C#

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

Read more in article
Dictionary Vs Hashtable Comparison In .NET Image

Dictionary Vs Hashtable Comparison In .NET

In .NET, 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 C# Dictionary Image

Check If The Key Exists In The C# Dictionary

In C#, 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 C# Sort Method for Dictionary Values Image

Best C# 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 In C# Image

How To Update Dictionary Values In C#

TryGetValue is the best method in C# 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 Using .NET Image

Get The Dictionary Keys By Their Value Using .NET

The best way in .NET 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 In C# Image

Best Way To Iterate Through A Dictionary In C#

Dictionary fastest C# 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 and List In C# Image

A Comparison Between IEnumerable and List In C#

In C#, 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 In C# Image

Convert A System Array To A List In C#

The fastest C# method for converting a system array to a list is to use an array cast and then use ToList. It is short and compact and easy to read.

Read more in article
Understanding The Best C# Set Theory Methods Between Lists Image

Understanding The Best C# 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 C# List Image

Remove Duplicate Items from A C# List

The best C# method for getting unique items from a list is to use a combination of HashSet and List. It has good performance and the order of the items is preserved.

Read more in article
Clone A C# List In Depth Review Image

Clone A C# List In Depth Review

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

Read more in article
Introduction to C# Lists Image

Introduction to C# Lists

C# 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
String | Puzzled By C# Image

String | Puzzled By C#

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 | Puzzled By C# Image

Code Snippets | Puzzled By C#

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 In C# Image

How To Find An Item In The List In C#

The best C# method for finding an item in a list is the List Find method, however, the best collection type for finding an item in the dictionary.

Read more in article
Convert A List To A String With A Delimiter In .NET Image

Convert A List To A String With A Delimiter In .NET

The best .NET 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 set up.

Read more in article
How To Initialize A List In .NET Image

How To Initialize A List In .NET

Initializing the C# 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 | Puzzled By C# Image

Best Way To Sort A List | Puzzled By C#

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 C# List By Index Image

Access Items From A C# List By Index

The best way in C# to access an item on 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 In C# Image

Get A Substring Between Two Strings In C#

The most effective function for getting a substring between two C# strings is the span slice. Speed is an important factor because that has an impact on the end user.

Read more in article
Analysis Of Getting First N Characters Methods In .NET Image

Analysis Of Getting First N Characters Methods In .NET

The best .NET method for getting the first n characters is span slice. Performance is the best metric to determine which is best because it affects the end users.

Read more in article
How Best In C# To Get Last N Characters Image

How Best In C# To Get Last N Characters

The best way in C# to get the last n characters is to use a string substring. It has one of the fastest methods and is readable so you don't have to guess what it does.

Read more in article
Get A Substring After Finding A Keyword In C# Image

Get A Substring After Finding A Keyword In C#

The overall best way in C# to solve getting a substring after finding a keyword is with Span Slice because of the huge performance gain.

Read more in article
Best C# First Character Removal Function In A String Image

Best C# First Character Removal Function In A String

In C#, 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 C# String Image

Efficiently Remove The First Keyword Occurrence From A C# String

Data can have duplicated and errors can be in the inputs and fields it is important to efficiently remove the first keyword occurrence from a C# string.

Read more in article
In C#, Get A Substring Before Or After A Certain Character Image

In C#, Get A Substring Before Or After A Certain Character

Getting a substring before or after a certain character is common in parsing C# strings, user data, database data, and automatic data generated by scripts.

Read more in article
Examining The Details Of String Equals In C# Image

Examining The Details Of String Equals In C#

In C#, String Equals comparing two strings to find out if they are exactly the same. The comparison is case-sensitive and usually used in conditional statements.

Read more in article
In C#, String Replace In Depth Image

In C#, String Replace In Depth

In C#, the method string replace is a string and character substitute with another string. It finds the characters and then replaces them it a new set of characters.

Read more in article
Walkthrough of the String Trim Function In C# Image

Walkthrough of the String Trim Function In C#

In C#, 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 | Puzzled By C# Image

Using String Insert Effectively | Puzzled By C#

String insert puts a single string between a section of the string. The first parameter is an index of insert and the second parameter is the string to insert.

Read more in article
Best Ways To Use String Remove In C#     Image

Best Ways To Use String Remove In C#

In C#, 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 In C# Image

How To Use SubString In C#

The substring method in C# copies a chunks 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 In .NET Image

Array Vs List Vs Linked List In .NET

In .NET, Array vs Lists vs Linked Lists is a common collection type, each has pros and cons so it is important to understand these as we make our collection choices.

Read more in article
Fix For C# Default Parameter Value Not Compile Time Constant Error Image

Fix For C# Default Parameter Value Not Compile Time Constant Error

In C#, the exception CS1736:Default parameter value must be a compile-time constant comes when assigning an optional parameter value is not a constant or default value.

Read more in article
C# Dictionary Best Practices And What To Avoid Image

C# Dictionary Best Practices And What To Avoid

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

Read more in article
Copying Files via Project Script On Build | Puzzled By C# Image

Copying Files via Project Script On Build | Puzzled By C#

One way to copy files to the output folder is to edit the .csproj file and add a command to copy files from a certain directory into the output folder.

Read more in article
List vs Dictionary .NET Collection Types Image

List vs Dictionary .NET Collection Types

In .NET, list and dictionary are useful collection types. They are accessible 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 | Puzzled By C# Image

Identify If a DLL is 32bit or 64bit | Puzzled By C#

Want to find out if a DLL or assembly is targeting 32bit or 64bit then Visual Studio comes with a handy tool called Corflags accessed by the command prompt.

Read more in article
Hex To Int Conversion In C# Image

Hex To Int Conversion In C#

Hex is a base 16 number system and C# has a built-in function that can convert a string hex value into an int value.

Read more in article
String Vs StringBuilder Comparison In .NET Image

String Vs StringBuilder Comparison In .NET

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

Read more in article
In C# Open A File Programmatically Image

In C# Open A 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 in .NET Image

New Line In StringBuilder in .NET

The new line in .NET is a special sequence that can be inserted into a string. Represented as a backslash n this works as if you pressed return on the keyboard.

Read more in article
In C#, Get A Substring Before Or After A Certain Character Image

In C#, Get A Substring Before Or After A Certain Character

Getting a substring before or after a certain character is common in parsing C# strings, user data, database data, and automatic data generated by scripts.

Read more in article
Fix For C# Default Parameter Value Not Compile Time Constant Error Image

Fix For C# Default Parameter Value Not Compile Time Constant Error

In C#, the exception CS1736:Default parameter value must be a compile-time constant comes when assigning an optional parameter value is not a constant or default value.

Read more in article
How To Update Dictionary Values In C# Image

How To Update Dictionary Values In C#

TryGetValue is the best method in C# 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 A Substring Between Two Strings In C# Image

Get A Substring Between Two Strings In C#

The most effective function for getting a substring between two C# strings is the span slice. Speed is an important factor because that has an impact on the end user.

Read more in article
Two Lists of Keys and Values Mapped To a Dictionary In C# Image

Two Lists of Keys and Values Mapped To a Dictionary In C#

Mapping two lists into a dictionary is best done manually. It has the best performance and also can handle duplicate keys without throwing exceptions.

Read more in article
Array Vs List Vs Linked List In .NET Image

Array Vs List Vs Linked List In .NET

In .NET, Array vs Lists vs Linked Lists is a common collection type, each has pros and cons so it is important to understand these as we make our collection choices.

Read more in article
Best Way To Iterate Through A Dictionary In C# Image

Best Way To Iterate Through A Dictionary In C#

Dictionary fastest C# 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
Best C# Merging Method For Two Dictionaries Image

Best C# Merging Method For Two Dictionaries

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

Read more in article
Get C# Dictionary Element By Index Image

Get C# Dictionary Element By Index

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

Read more in article
How To Change A Dictionary Key In C# Image

How To Change A Dictionary Key In C#

Changing the C# 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
TryGetValue Vs ContainsKey With Indexer In .NET Image

TryGetValue Vs ContainsKey With Indexer In .NET

TryGetValue is the best .NET method for getting values from a dictionary. It performs better and takes up less code than using ContainsKey with Indexer.

Read more in article
C# Dictionary Best Practices And What To Avoid Image

C# Dictionary Best Practices And What To Avoid

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

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

Check If The Key Exists In The C# Dictionary

In C#, 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
How To Initialize C# Arrays Image

How To Initialize C# Arrays

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

Read more in article
 How To Find An Item In The List In C# Image

How To Find An Item In The List In C#

The best C# method for finding an item in a list is the List Find method, however, the best collection type for finding an item in the dictionary.

Read more in article
6 C# Initializers To Get An Empty Array In 2023  Image

6 C# Initializers To Get An Empty Array In 2023

In C#, 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
Best C# Sort Method for Dictionary Values Image

Best C# 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 Install Visual Studio Image

How To Install Visual Studio

This is a step-by-step guild to install Visual Studio. It is a great IDE to work with and has rich features and debugging tools.

Read more in article
C# Dictionary With One To Many Relationship Image

C# Dictionary With One To Many Relationship

There are a couple of ways to have a one-to-many collection type. You can use a dictionary in C# with a List or List of KeyValuePairs. Each with pros and cons.

Read more in article
Make A .NET Dictionary Key Case Insensitive Image

Make A .NET Dictionary Key Case Insensitive

In .NET, 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