Nizamuddin Siddiqui

Nizamuddin Siddiqui

1,958 Articles Published

Articles by Nizamuddin Siddiqui

Page 22 of 196

How to implement Open Closed principle using C#?

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

The Open Closed Principle (OCP) is one of the five SOLID principles of object-oriented programming. It states that software entities like classes, modules and functions should be open for extension but closed for modifications. Definition The Open Closed Principle states that the design and writing of code should be done in a way that new functionality can be added with minimum changes to existing code. The design should allow adding new functionality through new classes while keeping existing code unchanged as much as possible. Open Closed Principle OPEN ...

Read More

How to calculate the total number of items defined in an enum in C#?

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

An enum is a special value type that represents a group of named constants. When working with enums, you often need to know how many items are defined in the enum. C# provides several methods to calculate the total count of enum items. Syntax Following are the main approaches to get the total count of enum items − // Using Enum.GetNames() int count = Enum.GetNames(typeof(EnumName)).Length; // Using Enum.GetValues() int count = Enum.GetValues(typeof(EnumName)).Length; Using Enum.GetNames() Method The Enum.GetNames() method returns an array of string names for all enum values. The Length property gives ...

Read More

How to find the Number of CPU Cores in C#?

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

Finding the number of CPU cores in C# involves understanding different types of processor information. There are several ways to get processor details − Physical processors − The actual number of CPU sockets CPU cores − The number of physical processing units Logical processors − The number of threads the CPU can handle simultaneously These values can differ significantly. For example, a machine with 2 dual-core hyper-threading-enabled processors has 2 physical processors, 4 cores, and 8 logical processors. CPU Architecture Example Physical CPU 1 ...

Read More

How to get the thread ID from a thread in C#?

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

A thread is defined as the execution path of a program. Each thread defines a unique flow of control. If your application involves complicated and time-consuming operations, then it is often helpful to set different execution paths or threads, with each thread performing a particular job. Threads are lightweight processes. One common example of use of thread is implementation of concurrent programming by modern operating systems. Use of threads saves wastage of CPU cycle and increase efficiency of an application. In C#, the System.Threading.Thread class is used for working with threads. It allows creating and accessing individual threads ...

Read More

How to display methods and properties using reflection in C#?

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

Reflection is the process of examining and describing the metadata of types, methods, and properties in a code at runtime. The System.Reflection namespace enables you to obtain data about loaded assemblies, the elements within them like classes, methods, and value types. The most commonly used classes in System.Reflection include Assembly, AssemblyName, ConstructorInfo, MethodInfo, ParameterInfo, EventInfo, PropertyInfo, and MemberInfo. Syntax Following is the syntax for getting type information using reflection − TypeInfo typeInfo = typeof(ClassName).GetTypeInfo(); IEnumerable properties = typeInfo.DeclaredProperties; IEnumerable methods = typeInfo.DeclaredMethods; Using Reflection to Display Properties and Methods Reflection allows you ...

Read More

How to read a CSV file and store the values into an array in C#?

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

A CSV file is a comma-separated values file that stores data in a tabular format. Most business organizations use CSV files to store and exchange structured data because of their simplicity and wide compatibility. In C#, we can read CSV files using the StreamReader class along with File.OpenRead() method. The data can then be parsed and stored in arrays or collections for further processing. Syntax Following is the basic syntax for reading a CSV file − StreamReader reader = new StreamReader(File.OpenRead(filePath)); while (!reader.EndOfStream) { var line = reader.ReadLine(); ...

Read More

How to perform a left outer join using linq extension methods in C#?

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

In LINQ, a Left Outer Join includes all elements from the left collection and matching elements from the right collection. When there's no match in the right collection, the result still includes the left element with null values for the right side. This is different from an Inner Join, which only includes matching elements from both collections. Left Outer Join ensures that no records from the left collection are lost, even when they don't have corresponding matches in the right collection. Syntax The Left Outer Join pattern using LINQ extension methods follows this structure − ...

Read More

What does LINQ return when the results are empty in C#?

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

Language-Integrated Query (LINQ) is a set of technologies that integrates query capabilities directly into the C# language. When LINQ queries return no results, the behavior depends on which LINQ method you use. LINQ queries can be written for SQL Server databases, XML documents, ADO.NET Datasets, and any collection that supports IEnumerable or IEnumerable. Understanding what happens when queries return empty results is crucial for avoiding runtime exceptions. Common LINQ Methods and Empty Results LINQ Method Empty Result Behavior ToList() Returns an empty List ToArray() Returns an empty array ...

Read More

How to post data to specific URL using WebClient in C#?

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

The WebClient class in C# provides simple methods for sending and receiving data from web servers. It's particularly useful for posting data to specific URLs, making it easy to interact with Web APIs without complex HTTP handling. WebClient offers methods like UploadString, UploadData, and UploadValues for posting different types of data. While HttpClient is the modern alternative, WebClient remains useful for simple scenarios. Namespace and Assembly Namespace: System.Net Assembly: System.Net.WebClient.dll Syntax Following is the basic syntax for posting data using WebClient − using (WebClient client = new WebClient()) { ...

Read More

How to write Regex for numbers only in C#?

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

Regular expressions (regex) are patterns used to match specific text formats. In C#, you can create regex patterns to validate that input contains only numbers. The System.Text.RegularExpressions.Regex class provides methods to test strings against these patterns. For numbers-only validation, you need to understand the key regex metacharacters and how to construct patterns that accept different numeric formats like integers, decimals, and negative numbers. Syntax Basic regex pattern for numbers only − Regex regex = new Regex(@"^[0-9]+$"); Pattern for numbers with optional decimal point − Regex regex = new Regex(@"^[0-9]+\.?[0-9]*$"); ...

Read More
Showing 211–220 of 1,958 articles
« Prev 1 20 21 22 23 24 196 Next »
Advertisements