Category: C#

C# Compiler Warning – CS4026 the callermembernameattribute applied to

In this blog post, you’ll learn more about the C# Compiler Warning – CS4026 and the related message description C# Compiler Warning Code CS4026 C# Compiler Description for the Code :CS4026 The CallerMemberNameAttribute applied to parameter ‘{0}’ will have no effect because it applies to a member that is used in contexts that do not allow optional arguments

How to Create an Empty array without defining the size in C# ?

When we create an array in C# , we tend to define the size of the array as shown below. Can we create an array without defining the size ? The best option in this  scenario is to use the collection. You can use the Generic List which allows you to add as many items as possible and then you can use the ToArray method…

How to set a property value by reflection in C# ?

There are times when you want to set the property of an object using reflection in C#. Below is a sample code snippet demonstrating how to do it taking the Employee class as an example and Name as the property. How to set a property value by reflection in C# ?

C# Compiler Error – CS8344 foreach statement cannot operate on enum

In this blog post, you’ll learn more about the C# Compiler Error – CS8344 and the related message description C# Compiler Error Code CS8344 C# Compiler Description for the Code :CS8344 foreach statement cannot operate on enumerators of type ‘{0}’ in async or iterator methods because ‘{0}’ is a ref struct.

Null Coalescing Operator (??) in C#

The .NET Framework provides the Null Coalescing Operator (??) which is a kind of binary operator and enables the developers to quickly check for the null values . The Null Coalescing Operator (??) in C# can be used with Nullable types as well as reference types . For example , a??b .If a is not null then assign the value a else take the value…

How to Get Connection String from App.config file in C# ?

If you want to get the connection string from the App.config file in C# , you can use the ConfigurationManager class to achieve the same. How to Get Connection String from App.config file in C# ? Assume that the configuration file contains the following Below is the code snippet to get the connection string.

How to Parse a string to Nullable Int in C# ?

Below is a sample code snippet demonstrating how you can convert a string to Nnullable Int in C#. How to Parse a string to Nullable Int in C# ? We use the int.Parse and based on its return value , assign the null or integer value to the Nullable Int.

How to Get the Name of the Anonymous class(type) in C# ?

Below is a sample code snippet which gets the name of the anonymous class . In the below example , the Name and the ID property is set which is anonymous where the type is not specified. When trying to find out the type of the anonymous type , you will get the type as shown in the screenshot below. How to Get the Name…