C# Code Snippets DateTime

C# DateTime

In this code snippet, we will take a look at DateTime in C#. DateTime is used to represent dates and times in code. The DateTime class contains many useful methods to manipulate the date(formatting the date, adding/subtracting years, months, days, hours, …). Let’s have a look at the code below to see how to use DateTime.

Useful Resources For Software Engineers

Useful Software Engineering Resources

It’s hard to remember everything you learn over the years especially if you don’t use it very often. That’s why I think it’s good to have a compilation of cheatsheets, reference books or other types of resources like blog posts/videos/PDFs. So in this post, I will “bookmark” some useful software engineering resources and cheatsheets for myself(or anyone else who stumbles upon this post).

Code Snippets Uploading Files

File Uploads With JS And C# Azure Functions

In this code snippet, we’ll learn how to upload files with Javascript. We will use the input HTML element and set its type to “file”. Then javascript can be used to retrieve the selected file from the input element and send it to the backend. You can use whatever you want for your backend: nodejs, PHP,  Java or in this case I will use a C# Azure function.

C# Code Snippets String Interpolation

C# String Interpolation

In this tutorial, we will take a look at string interpolation in C#. To enable string interpolation put the $ character before the string. Now variables in brackets can be put straight into a string. This is a bit more convenient compared to splitting up as string, putting the desired variables in between the strings and than concatenating it all together.

C# Code Snippets @ and String Literals

C# @ And String Literals

In this tutorial, we will take a look at string literals and the @ character in C#. In C# the @ character can either be used to make reserved keywords available as variable names or it can be used to make a string literal. A string literal takes everything in the string literally. For example, you do not have to escape a \ with \\ . Your string can now also span multiple rows in the editor. This can be useful when making SQL statements or HTML, XML, …

C# Code Snippets Break and Continue

C# Break and Continue

In this code snippet, we will take a look at break and continue in C#. break is used to break out of a code block. If done in a loop it will essentially stop the loop from executing. continue is used to inside a loop to skip the current iteration.

C# Code Snippets goto Keyword

C# goto Keyword

In this code snippet, we will take a look at the goto keyword in C#. goto is used to move the control of your program to a label you define beforehand. This can be useful to get out of nested loops, if statements or any nested code blocks in general. You can even make a DIY loop or method using the goto keyword 😁(But you should of course use the regular loops and methods).

C# Code Snippets TPL(Task Parallel Library) and Tasks

C# TPL(Task Parallel Library) And Tasks

In this code snippet, we will take a look at the TPL(Task Parallel Library) in C#. If you read some of my other posts on threading you will know that it can be quite complicated and laborious for the developers to implement parallelism into their programs(deadlocks, cancellation, thread pooling, getting data back from the thread, …). The Task Parallel Library(TPL) takes care of a lot of these things and or makes them easier manage.

C# Code Snippets Thread Pooling

C# Thread Pooling

In this tutorial, we will take a look at thread pools in .NET and C#. Creating threads and disposing of them when a task is done can be an expensive operation to perform as it uses up time and memory. To mitigate this we can use a thread pool which is essentially a collection of pre instantiated threads. We can assign tasks to these threads. When the task is completed the thread gets returned to the thread pool instead of being disposed of.

Advertisment ad adsense adlogger