Nizamuddin Siddiqui

Nizamuddin Siddiqui

1,958 Articles Published

Articles by Nizamuddin Siddiqui

Page 13 of 196

What is an Optional parameter in C#?

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

By default, all parameters of a method are required. However, C# allows you to define optional parameters that do not force you to pass arguments at calling time. This means you can call a method without passing values for some parameters. Optional parameters contain default values in the function definition. If you do not pass an argument for an optional parameter at calling time, the default value is used automatically. There are different ways to make a parameter optional in C#. Syntax Following is the syntax for declaring optional parameters using default values − ...

Read More

How to download a file from a URL in C#?

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

A file can be downloaded from a URL using WebClient, which is available in the System.Net namespace. The WebClient class provides common methods for sending data to or receiving data from any local, intranet, or Internet resource identified by a URI. The WebClient class uses the WebRequest class internally to provide access to web resources. It offers a simple, high-level interface for downloading files without dealing with complex HTTP protocols directly. Syntax Following is the syntax for downloading a file using WebClient.DownloadFile method − WebClient client = new WebClient(); client.DownloadFile("sourceUrl", "destinationPath"); Parameters ...

Read More

How to make a method deprecated in C#?

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

The Obsolete Attribute marks elements like classes, methods, properties, fields, delegates, and many others within our code as deprecated or obsolete. The attribute is read at compile time and is used to generate a warning or an error to the developer. This attribute can help if we have ever wanted to make sure programmers use newer versions of methods. It also makes it easier when we are transitioning from older methods to newer ones. Marking an item as obsolete warns users that program elements will be removed in future versions of the code base. This attribute is found ...

Read More

What is Interface segregation principle and how to implement it in C#?

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

The Interface Segregation Principle (ISP) is the fourth principle of SOLID design principles. It states that clients should not be forced to depend upon interfaces that they don't use. Instead of creating one large interface with many methods, it's better to create multiple smaller, focused interfaces that serve specific purposes. This principle promotes high cohesion and loose coupling by ensuring that classes only implement the methods they actually need, making the code more maintainable and flexible. Syntax Following is the syntax for creating segregated interfaces − public interface ISpecificInterface { // Only ...

Read More

What is the difference between Foreach and Parallel.Foreach in C#?

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

The foreach loop in C# runs on a single thread and processes items sequentially one by one. In contrast, Parallel.ForEach utilizes multiple threads to process items concurrently, potentially improving performance for CPU-intensive operations on large collections. The key difference is that Parallel.ForEach can distribute work across multiple threads, while the standard foreach executes on a single thread. To use Parallel.ForEach, you need to import the System.Threading.Tasks namespace. Syntax Following is the syntax for a standard foreach loop − foreach (var item in collection) { // sequential processing } Following is ...

Read More

What is the difference between Task.WhenAll() and Task.WaitAll() in C#?

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

The Task.WaitAll() and Task.WhenAll() methods in C# serve different purposes when working with multiple asynchronous tasks. Task.WaitAll() blocks the current thread until all tasks complete, while Task.WhenAll() returns a new task that represents the completion of all provided tasks without blocking the calling thread. Understanding the difference between these methods is crucial for building responsive applications, especially those with user interfaces where blocking the main thread can freeze the UI. Syntax Following is the syntax for Task.WaitAll() − Task.WaitAll(task1, task2, task3); // or with timeout Task.WaitAll(new Task[] { task1, task2 }, TimeSpan.FromSeconds(30)); Following ...

Read More

How to update the value stored in a Dictionary in C#?

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

In C#, Dictionary is a generic collection which is generally used to store key/value pairs. In Dictionary, the key cannot be null, but value can be. A key must be unique. Duplicate keys are not allowed if we try to use duplicate key then compiler will throw an exception. As mentioned above a value in a dictionary can be updated by using its key as the key is unique for every value. Syntax Following is the syntax for updating a dictionary value − myDictionary[myKey] = myNewValue; You can also use the TryGetValue method ...

Read More

What is the difference between FromBody and FromUri attributes in C# ASP.NETnWebAPI?

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

In ASP.NET Web API, parameter binding determines how action method parameters receive values from HTTP requests. The [FromUri] and [FromBody] attributes control the source of parameter data, providing explicit control over this binding process. The FromUri attribute forces Web API to bind parameters from the URI query string, route data, or headers instead of the request body. The FromBody attribute instructs Web API to read parameter values from the HTTP request body using formatters like JSON or XML. Syntax Following is the syntax for using [FromUri] attribute − public IActionResult Method([FromUri] ModelClass model) { ...

Read More

How to create Guid value in C#?

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

A Globally Unique Identifier or Guid represents a 128-bit identification number that is mathematically guaranteed to be unique across multiple systems and distributed applications. The total number of unique keys (approximately 3.40282366×10³⁸) is so large that the probability of generating the same number twice is negligible. GUIDs are commonly used in applications where unique identification is critical, such as database primary keys, transaction IDs, or session identifiers. They are typically displayed as a sequence of hexadecimal digits like 3F2504E0-4F89-11D3-9A0C-0305E82C3301. Syntax The Guid structure is present in the System namespace. Following are the most common ways to create ...

Read More

What are the various return types of a controller action in C# ASP.NET WebAPI?

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

ASP.NET Web API controller actions can return different types depending on your application's requirements. Understanding these return types helps you choose the most appropriate approach for your specific scenarios. Available Return Types Void − Returns no content with HTTP 204 status Primitive/Complex Types − Returns data directly with automatic serialization HttpResponseMessage − Provides full control over the HTTP response IHttpActionResult − Offers a cleaner, testable approach to response creation Web API Return Type Evolution Void 204 No Content Primitive/ ...

Read More
Showing 121–130 of 1,958 articles
« Prev 1 11 12 13 14 15 196 Next »
Advertisements