menu icon

CSHARP Blogs

Convert String To Datetime In C#

Convert String To Datetime In C#

Author: Sameer Saini Date Published: July 28, 2022

This blog post will teach us how to convert a string to DateTime in C#. Let's say you have a datetime string with a date time value and now you want to perform some date calculations or checks or something else, you would need to convert this string to date in C#.

Read More
Check If String Is A Number In C#

Check If String Is A Number In C#

Author: Sameer Saini Date Published: July 28, 2022

In this blog post, we will learn how to check if a string is a proper number or integer in C#. Let's say you have a code in which you are getting a age as a string from a database call and you want to check if this string is a number or not before you could use it, this is where this check would be handy.

Read More
Convert String To Float In C#

Convert String To Float In C#

Author: Sameer Saini Date Published: June 12, 2022

In this blog post, we are going to learn how we can convert a string to float in C#. If you have a string that has a floating-point value or a double stored in it, and you want to convert the string to a float so that you can use it in your application.

Read More
Get Int Value From Enum In C# - Convert Enum To Int In C#

Get Int Value From Enum In C# - Convert Enum To Int In C#

Author: Sameer Saini Date Published: June 12, 2022

In this blog post, we are going to learn how we can get an Int value from Enum in C#. As we know, An enumeration type (or enum type) is a value type defined by a set of named constants of the underlying integral numeric type.</p> <p>We can get the integral value of an enum and can use it inside our C# application.

Read More
Get The First Character Of A String In C#

Get The First Character Of A String In C#

Author: Sameer Saini Date Published: May 31, 2022

In this blog post, we are going to learn how we can get the first character of a string in C#. We will discuss 2 methods by which we can get the first character of a string. Just note that you should still check if the string is null or empty to avoid any runtime exceptions.

Read More
Convert List To Dictionary In C#

Convert List To Dictionary In C#

Author: Sameer Saini Date Published: May 31, 2022

In this blog post, we will learn how we can convert a list to a dictionary in C#. Let's say you have a list and you want to convert it to a dictionary so that you can have defined key value pairs so you can use them, this is where this conversion from a list to dictionary comes in handy.

Read More
Calculate Age From Date Of Birth (DateTime Birthdate) In C#

Calculate Age From Date Of Birth (DateTime Birthdate) In C#

Author: Sameer Saini Date Published: May 31, 2022

In this blog post, we will learn how we can calculate the age of a person from their birthdate (birthday) in C#. To calculate the age of the person as of today's date, we need two variables, today's date and the birthdate(birth date) of the person for which we want to calculate the age.

Read More
Get The Last Character Of A String In C#

Get The Last Character Of A String In C#

Author: Sameer Saini Date Published: May 30, 2022

In this blog post, we are going to learn how we can get the last character of a string in C#. There can be many use cases where this might be necessary.

Read More
Reverse A String In C# - 2 Ways To Reverse A String

Reverse A String In C# - 2 Ways To Reverse A String

Author: Sameer Saini Date Published: May 22, 2022

In this blog post, we will see how we can reverse a string in C#. Reversing a string can be used in a few different scenarios. One of the use case can be an interview question.

Read More
Get File Size In C#

Get File Size In C#

Author: Sameer Saini Date Published: May 22, 2022

In this blog post, we will see how we can get the size of a file in C#. To get a file size in C#, we have to use the Length property on the FileInfo.

Read More
Convert String To Hex In C#

Convert String To Hex In C#

Author: Sameer Saini Date Published: May 22, 2022

In this blog post, we will see how we can convert a string to hex in C#. We will look at 3 ways by which we can easily convert a string to hex in C#.

Read More
Char Array To String In C#

Char Array To String In C#

Author: Sameer Saini Date Published: April 06, 2022

In this blog post, we will learn how to convert a <b>Char Array To String</b> in C#. A char array is an array of character types. That means they hold a single character value in each of its elements.

Read More
C# Dictionary Foreach - Iterate Over Dictionary C#

C# Dictionary Foreach - Iterate Over Dictionary C#

Author: Sameer Saini Date Published: April 05, 2022

In this blog post, we will learn how to iterate over a dictionary in C#. We will use a few different ways to iterate over the dictionary.

Read More
C# Exit Foreach Loop - Break Our Of Foreach Loop In C# - Break Keyword In C#

C# Exit Foreach Loop - Break Our Of Foreach Loop In C# - Break Keyword In C#

Author: Sameer Saini Date Published: April 05, 2022

In this blog post, we will see how to exit a for or a foreach loop in C#. There can be a use case where you are checking a condition in a loop where you are iterating through a list or an array. When this condition is met, you want to break from this loop and exit foreach loop.

Read More
Wait For X Seconds In C# - Add Delay In C#

Wait For X Seconds In C# - Add Delay In C#

Author: Sameer Saini Date Published: March 30, 2022

In this blog post, we will learn a couple of ways by which we can wait for X seconds in C# and delay execution. There can be a few use cases for adding a delay or for waiting for X seconds before you resume execution of your code in C# such as printing records back to the console, adding an explicit delay to mock or stub a slow running server or a backend service, etc.

Read More
C# Tab Character - Add Tab In String C#

C# Tab Character - Add Tab In String C#

Author: Sameer Saini Date Published: March 28, 2022

In this blog post, we will learn how we can add a tab in string in C#. There are a lot of places in your code where you would feel the need to add a tab character in C#.

Read More
C# Shuffle List - Shuffle A List In C#

C# Shuffle List - Shuffle A List In C#

Author: Sameer Saini Date Published: March 28, 2022

Do you want to Shuffle A List In C#? In this blog post, we will show you how you can shuffle a list in C# using the Random function.

Read More
C# Multiline String - Add New Line In String C#

C# Multiline String - Add New Line In String C#

Author: Sameer Saini Date Published: March 26, 2022

Let's learn to create a multiline string in C#. For readability purposes, sometimes we have to split a string into a multiline string in C#. To our luck, there are several ways by which we can have multiline strings in C#.

Read More
C# Double Question Mark Operator - Null-Coalescing Operator C#

C# Double Question Mark Operator - Null-Coalescing Operator C#

Author: Sameer Saini Date Published: March 26, 2022

If you are reviewing a C# code and you've come across a double question mark operator (??), you must be wondering what does this double question mark operator does in C#. In this blog post, we will learn what this double question mark operator does and we will also see a few usages of this operator in some code examples.

Read More
C# Array Length - Get Length Of Array Using Array.Length() Property

C# Array Length - Get Length Of Array Using Array.Length() Property

Author: Sameer Saini Date Published: March 26, 2022

In this blog post, we will learn how we can get the <b>length of array</b> in C#. This is really easy and we will see how we can use the property on any array that you want to get the length or the count of elements for. Let's see how we can get the length of the array using a code example.

Read More
3 Ways To Convert An Array To List In C#

3 Ways To Convert An Array To List In C#

Author: Sameer Saini Date Published: March 25, 2022

In this blog post, we will convert an <b>Array To List in C#. If you are dealing with Arrays in a code base, you may end up converting that to a much more powerful List in C# for several reasons. For one, it's much easier to append items to a list than to an array and you can use the power of Linq in lists easily.

Read More
Exponent In C# - Exponent Operator In C# Using Math.Pow() Method

Exponent In C# - Exponent Operator In C# Using Math.Pow() Method

Author: Sameer Saini Date Published: March 25, 2022

Ever wondered, how can we evaluate an exponent in C#? In this blog post, we will discuss how we add an exponent in C#. In this code example, we will use Math.Pow() method to evaluate an exponent in C#.

Read More
Pass Function As Parameter Using C#

Pass Function As Parameter Using C#

Author: Sameer Saini Date Published: March 24, 2022

In this blog post, we will learn how we can pass a function as a parameter in C# or a method as a parameter in C#. Pass Function As A Parameter To Another Function In C# Using Func Delegate.

Read More
Get List Length C# - Get Count Of Elements In A List C#

Get List Length C# - Get Count Of Elements In A List C#

Author: Sameer Saini Date Published: March 24, 2022

In some scenarios, we need to get the count of elements in a list in C# or the length of a list in C#. These are the cases where we need to check if the length or the number of elements in the list is greater than or less than some number.

Read More
Convert Stream To Byte Array In C#

Convert Stream To Byte Array In C#

Author: Sameer Saini Date Published: March 24, 2022

In this blog post, we will see how we can convert a stream to byte array in C# using the .ToArray() method available on the MemoryStream class. We will use the .ToArray() method available on the MemoryStream class and convert stream to byte array.

Read More
Build REST APIs with ASP.NET CORE WEB API & Entity Framework

Build REST APIs with ASP.NET CORE WEB API & Entity Framework

Author: Sameer Saini Date Published: March 24, 2022

This is a complete guide to creating a highly scalable ASP.NET CORE RESTful WEB API using .NET Core Version 6 (.NET 6), Entity Framework Core and SQL Server database. This course is for all skill levels and is best suited for beginners and intermediate developers who have gained knowledge in C# and ASP.NET framework and want to use their skills to learn highly scalable WEB APIs using REST principles. In this WEB API course, we will use ASPNET Core Version 6 (also known as .NET 6) and create a RESTful WEB API.

Read More
How To Initialize Array In C#

How To Initialize Array In C#

Author: Sameer Saini Date Published: March 24, 2022

As we know an Array in C# is a collection of objects. This Array could be of any type, for example, a string array or an int Array. Before we can use an Array and do something with it like assign values or append values or iterate on it, we need to initialize the array.

Read More
Create ASP.NET Core WEB API CRUD With Angular UI

Create ASP.NET Core WEB API CRUD With Angular UI

Author: Sameer Saini Date Published: March 15, 2022

In this blog post, we will create an ASP.NET CORE WEB API CRUD Application With Angular CRUD operations. We will use ASP.NET CORE 6 or .NET 6 to create our WEB API and we will connect our API to an ANGULAR 13 application. This Angular 13 application will perform CRUD operations on the ASP.NET CORE WEB API.

Read More
Get Random Number Between 1 and 100 C#

Get Random Number Between 1 and 100 C#

Author: Sameer Saini Date Published: March 07, 2022

In this blog post, we will get a random number between 1 and 100 using C#. We will use the Random class that C# provides us. We will instantiate the <b>Random</b> class and then provide a range to the .Next() method.

Read More
Add Or Append Item To An Array C#

Add Or Append Item To An Array C#

Author: Sameer Saini Date Published: March 06, 2022

In this post, we will add to an array in C#. Adding an element to array means to add a new item or an element of type to an existing array. In C#, we have a few different options to add or append to an existing array.

Read More
Split String In C# - String.Split() Method In C#

Split String In C# - String.Split() Method In C#

Author: Sameer Saini Date Published: March 05, 2022

In our day-to-day scenarios, we sometimes end up in a scenario where we have to split a delimited string to a list. If you are using the C# language, splitting a string is an easy task. In this blog post, we will learn how we can split a string in C# using the <b>string.Split()</b> method and we will also use a delimiter such as a comma or a space to split the string into a list or an array.

Read More
Deserialize Json To Object In C# - Parse JSON To Object

Deserialize Json To Object In C# - Parse JSON To Object

Author: Sameer Saini Date Published: March 04, 2022

In this blog post, we will learn how we can deserialize Json to an Object in C#. We will use the System.Text.Json namespace to deserialize Json to an Object in C#.

Read More
Serialize Object To Json In C# - JsonSerializer

Serialize Object To Json In C# - JsonSerializer

Author: Sameer Saini Date Published: March 03, 2022

In this blog post, we will learn how we can serialize an object to Json in C#. We will use the System.Text.Json namespace to serialize an object to Json in C#.

Read More
Iterate An Enum In C# - Looping Through All Enum Values In C#

Iterate An Enum In C# - Looping Through All Enum Values In C#

Author: Sameer Saini Date Published: March 02, 2022

We often find a use case where we have to iterate through the values of something to get the job done. This iteration of looping can be for some calculations or display stuff, but we always iterate on lists or arrays and get data out of each item in that list or array. In this blog post, we will use loops, but not on a list or array, we will iterate an enum today.

Read More
Join An Array In C#

Join An Array In C#

Author: Sameer Saini Date Published: March 02, 2022

In this blog post, we will learn how we can join an array in C#. Joining an array means joining the values of the array using a delimiter. When we join an array in C#, we loop through all the values and insert a delimiter value (if any) to join and make the result. For example, an array ["John", "Julie", "Sameer"] would be joined to make a string "John,Julie,Sameer" if the delimiter was a comma value. How do we achieve this? In C#, we use the Join() method that is available to us in the sealed class String.

Read More
Find An Item In List Using LINQ - C#

Find An Item In List Using LINQ - C#

Author: Sameer Saini Date Published: March 02, 2022

Have you been in a situation where you have a list and you have to find an item in the list? C# offers us an easy way to find an item in a list using the .Find() method. The Find() method searches for an element that matches the conditions defined by the specified predicate, and returns the first occurrence within the entire List.

Read More
Convert An Enum To String In C#

Convert An Enum To String In C#

Author: Sameer Saini Date Published: March 02, 2022

In this blog post, we will convert an Enum to string in C#. An enumeration type (or enum type) is a value type defined by a set of named constants of the underlying integral numeric type. We can convert an enum to a string using the .ToString() method on the Enum.

Read More
Empty GUID In C# - Create Or Get An Empty GUID In C#

Empty GUID In C# - Create Or Get An Empty GUID In C#

Author: Sameer Saini Date Published: February 28, 2022

In a C# ASP.NET website or application, sometimes we need to check if a GUID being passed is empty or not. Sometimes, we also need to generate an empty GUID for some different use cases. In C#, we can easily create an empty or default GUID using the GUID static class that the system namespace provides us. We can also compare a GUID value to check whether it's an empty GUID.

Read More
How To Read Text File Using C#

How To Read Text File Using C#

Author: Sameer Saini Date Published: February 28, 2022

If you want to learn how you can read text from a text file using C#, you have come to the right blog post. In this one, we will go step by step and see how easily we can read a text file using C#

Read More
Get Random Number Using C#

Get Random Number Using C#

Author: Sameer Saini Date Published: February 28, 2022

C# gives us a class called Random that gives us a really easy way to create random numbers in between a range of 2 numbers (min and max). If no range is provided, the integer min and integer max values are taken. Note: The returned number or integer can be greater than or equal to min value but less than max value.

Read More
Get Current Directory In C#

Get Current Directory In C#

Author: Sameer Saini Date Published: February 28, 2022

There are a few ways in which we can get the current directory of the application using C#. All of the below are running for a console application created using .NET 6 and returns the current directory the application is running under.

Read More
Delete A File If Exists Using C#

Delete A File If Exists Using C#

Author: Sameer Saini Date Published: February 28, 2022

Sometimes we have a delete a file or create a new one but we are just not sure if there is already a file that exists? In such a case, it's good practice to check if the file exists, and if it does, then delete the file.

Read More
Get All Files From Directory Using C# - GetFiles Method

Get All Files From Directory Using C# - GetFiles Method

Author: Sameer Saini Date Published: February 25, 2022

In this blog post, we will have a look at how we can get all files from a specified directory using C#. C# gives us a really handy in-built method from which we can read a directory and it's information.

Read More
Add Items To List C#

Add Items To List C#

Author: Sameer Saini Date Published: February 22, 2022

A list represents a collection of strongly typed objects. This can be a list of integers, a list of strings, or a list of complex types. A list in C# is an easy way to maintain a collection of similar types and then using the functions that C# provides you can easily iterate on that list if you need to. There will be numerous use cases when you would need to add a new item to a list dynamically. For example, if you have a list of years that are from 2000 to 2020, now it's time to add the next 10 years to that list. You would need to dynamically add items to the list so that you can use them.

Read More