Tag: C#

How to disable editing of items in a combo box in c#?

When working in Win forms using C# and especially when you use the combo box , you would have noticed that by default the user can edit the values inside during the runtime. How to disable editing of items in a combo box in c# (win forms) ? Assuming that the combobox name is combobox1 , here the code to get this behavior.

How to Check if the Enum Value is Defined in C# ?

There are times when it is necessary to check if the constant name or numeric value is defined in the Enum . We can use the Enum.IsDefined method to verify this. How to Check if the Enum Value is Defined in C# ? Below is a sample code to demonstrate how to Check if the Enum Value is Defined in C# using Enum.IsDefined method. The…

How to retrieve integer value and remove all other strings in C# ?

If you want to retrieve the integer value and remove all other strings in C# , one can use the Regex.Replace method and apply regular expression easily and get only the integer part from a string. How to How to retrieve integer value and remove all other strings in C# ? Below is a sample sourecode demonstrating How to retrieve integer value and remove all…

What are the difference between class and structure in C#?

What are the difference between class and structure in C#? Structure Struct are value types. They can be empty but a null cannot be assigned to Struct Structs cannot contain explicit parameterless constructors. Doesn’t support Inheritance and cannot use the protected or protected internal modifier. A Struct always has a built-in public default constructor. Cannot use the “as” operator. Cannot have a destructor Cannot be…

Deferred Execution Example in LINQ and C#

The Query Operators are executed only when enumerated except few scenarios. For example, when you use the for/Foreach statement and iterate the items from the query result. Below is a sample code demonstrating the Deferred Execution in C#. Deferred Execution Example in LINQ and C#

How to detect if the Windows Phone App is running in KidsCorner using C#?

Below is a sample code snippet that demonstrates how to detect if the application in Windows Phone is running in Kids Corner using C#? The Windows.Phone.ApplicationModel.ApplicationProfile returns the value Default or Alternate. The default value indicates the normal mode whereas the Alternate indicates the Kids Corner mode. How to detect if the Windows Phone App is running in KidsCorner using C#?

How to validate a user in Active Directory using C#?

Do you want to validate a user with the login credentials like username and password of the user in Active Directory using C#? You can do it using the classes provided in the Directory Services namespace. You need to include the assemblies “System.DirectoryServices” and “System.DirectoryServices.AccountManagement” in your solution. How to validate a user in Active Directory using C#? Below is a sample code snippet demonstrating…

C# and LINQ – Finding all the elements of an integer array less than 35

Here’s a sample code snippet demonstrating how to find all the elements of an integer array that is less than 35 using LINQ in C#. The where keyword in C# is used to filter the elements from a collection based on the specified criteria. Ensure that you import the System.Linq namespace to your C# code. How to find all the elements of an integer array…