Nizamuddin Siddiqui

Nizamuddin Siddiqui

1,958 Articles Published

Articles by Nizamuddin Siddiqui

Page 8 of 196

How to check Minlength and Maxlength validation of a property in C# using Fluent Validation?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 17-Mar-2026 3K+ Views

FluentValidation is a popular .NET validation library that provides an easy way to validate model properties. The MinLength and MaxLength validators ensure that string properties meet specific length requirements, making them essential for input validation scenarios. Syntax Following is the syntax for using MaximumLength validator − RuleFor(x => x.PropertyName).MaximumLength(maxValue); Following is the syntax for using MinimumLength validator − RuleFor(x => x.PropertyName).MinimumLength(minValue); MaxLength Validator The MaximumLength validator ensures that the length of a string property does not exceed the specified maximum value. This validator is only valid on string properties. ...

Read More

How to convert IEnumerable to List and List back to IEnumerable in C#?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 17-Mar-2026 9K+ Views

IEnumerable is an interface that defines a single method GetEnumerator() and provides the foundation for iterating over collections. The List class is a concrete implementation that provides indexed access and manipulation methods for collections. Converting between these types is a common requirement in C# development. IEnumerable offers read-only iteration, while List provides full collection manipulation capabilities including adding, removing, and sorting elements. Converting IEnumerable to List The most efficient way to convert IEnumerable to List is using the ToList() extension method − Using ToList() Method using System; using System.Collections.Generic; using System.Linq; class Program ...

Read More

How to get all the directories and sub directories inside a path in C#?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 17-Mar-2026 26K+ Views

To get directories in C#, the Directory.GetDirectories method is used. This method returns the names of subdirectories (including their full paths) that match a specified search pattern in a given directory, with options to search subdirectories recursively. The method allows you to control the search scope using SearchOption enumeration values. The wildcard pattern * matches zero or more characters, enabling flexible directory matching. Syntax Following is the basic syntax for Directory.GetDirectories method − string[] Directory.GetDirectories(string path, string searchPattern, SearchOption searchOption) Parameters path − The relative or absolute path to the directory ...

Read More

What if we are not sure of the type of value that we want to store in a variable. How to handle this in C#?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 17-Mar-2026 124 Views

As C# is a strongly-typed language, every variable and constant has a pre-defined type. Before using any variable, we must tell the compiler what type of value a variable will store. If we are not sure about the type, then it is handled using dynamic programming. Dynamic programming is supported by the dynamic keyword, which allows variables to bypass compile-time type checking and have their types resolved at runtime. Syntax Following is the syntax for declaring a dynamic variable − dynamic variableName = value; The type of the variable is determined at runtime ...

Read More

What is the use of "is" keyword in C#?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 17-Mar-2026 429 Views

The is keyword in C# is used to check if an object is of a specific type or can be cast to that type. It returns a Boolean value — true if the object is compatible with the specified type, false otherwise. The is keyword is particularly useful for type checking before performing type conversions, ensuring safe downcasting in inheritance hierarchies, and working with polymorphic objects. Syntax Following is the syntax for using the is keyword − object is Type The is keyword can also be used with pattern matching (C# 7.0+) − ...

Read More

How to convert an integer to string with padding zero in C#?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 17-Mar-2026 2K+ Views

Converting an integer to a string with padding zeros is a common requirement in C# programming. This allows you to format numbers with a consistent width by adding leading zeros. There are several approaches to achieve this, each with its own syntax and use cases. Syntax Following are the common syntaxes for zero-padding integers − // Using PadLeft method number.ToString().PadLeft(width, '0'); // Using custom numeric format number.ToString("0000"); // Using standard numeric format number.ToString("D4"); // Using string interpolation $"{number:0000}" Using PadLeft Method The PadLeft method pads the beginning of a string ...

Read More

How to catch an exception thrown by an async void method in C#?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 17-Mar-2026 983 Views

In synchronous C# code, exceptions propagate up the call stack until they reach an appropriate catch block. However, exception handling in asynchronous methods behaves differently depending on the return type. An async method in C# can have three return types: void, Task, and Task. When an exception occurs in an async method with Task or Task return type, the exception is wrapped in an AggregateException and attached to the Task object. However, async void methods behave differently and present unique challenges for exception handling. Async Task vs Async Void Exception Handling Exception Handling: ...

Read More

How to store n number of lists of different types in a single generic list in C#?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 17-Mar-2026 849 Views

We can store n number of lists of different types in a single generic list by creating a list of List. This approach allows us to store lists containing integers, strings, or any other data type within a single container. Syntax Following is the syntax for creating a list that can hold multiple lists of different types − List containerList = new List(); Each inner list can store objects of any type − List innerList = new List(); innerList.Add(value); // value can be int, string, etc. containerList.Add(innerList); Using List of ...

Read More

What is the difference between int and Int32 in C#?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 17-Mar-2026 6K+ Views

Int32 is a type provided by .NET framework whereas int is an alias for Int32 in C# language. Both represent 32-bit signed integers and compile to identical code, making them functionally equivalent at runtime. Syntax Following is the syntax for declaring integers using both approaches − Int32 variable1 = value; int variable2 = value; Key Differences Aspect int Int32 Type C# language keyword (alias) .NET Framework type Namespace dependency No namespace required Requires System namespace Compilation Compiles to System.Int32 Direct .NET type ...

Read More

How to return multiple values to caller method in c#?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 17-Mar-2026 1K+ Views

Returning multiple values from a method in C# can be achieved through several approaches. The most modern and efficient approach is using ValueTuple, introduced in C# 7.0, which provides a lightweight mechanism for returning multiple values with optional named elements. ValueTuples are both performant and allow referencing by names the programmer chooses. They are available under the System.ValueTuple NuGet package for older framework versions. Syntax Following is the syntax for declaring a method that returns multiple values using ValueTuple − public (int, string, string) MethodName() { return (value1, value2, value3); } ...

Read More
Showing 71–80 of 1,958 articles
« Prev 1 6 7 8 9 10 196 Next »
Advertisements