Server Side Programming Articles

Page 745 of 2109

How to run multiple async tasks and waiting for them all to complete in C#?

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

In C#, there are several ways to run multiple asynchronous tasks and wait for them all to complete. The two main approaches are Task.WaitAll (synchronous blocking) and Task.WhenAll (asynchronous non-blocking). Task.WaitAll blocks the current thread until all tasks have completed execution, while Task.WhenAll returns a task that completes when all provided tasks have finished, without blocking the calling thread. Syntax Following is the syntax for using Task.WaitAll − Task.WaitAll(task1, task2, task3); Following is the syntax for using Task.WhenAll − await Task.WhenAll(task1, task2, task3); Using Task.WhenAll (Non-blocking) The Task.WhenAll ...

Read More

How to get formatted JSON in .NET using C#?

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

JSON formatting in C# allows you to control how JSON data is presented when serialized. The Newtonsoft.Json library provides formatting options through the Formatting enumeration to make JSON output more readable or compact as needed. Syntax Following is the syntax for serializing objects with different formatting options − string json = JsonConvert.SerializeObject(object, Formatting.Indented); string json = JsonConvert.SerializeObject(object, Formatting.None); Formatting Options Option Description Use Case Formatting.None No special formatting is applied. This is the default. Compact JSON for APIs and storage Formatting.Indented Child objects are ...

Read More

How to implement Open Closed principle using C#?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 17-Mar-2026 593 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 display methods and properties using reflection in C#?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 17-Mar-2026 349 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

Difference Between C# and C++

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 657 Views

C# and C++ are both powerful programming languages, but they serve different purposes and have distinct characteristics. Understanding their differences helps developers choose the right language for their projects. What is C#? C# is a general-purpose object-oriented programming language developed by Anders Hejlsberg and his team at Microsoft. It is pronounced as 'C sharp' and is considered a pure object-oriented programming language that runs on the .NET framework. Key characteristics of C# include − Automatic memory management through garbage collection Platform-specific (primarily Windows, though .NET Core enables cross-platform development) No ...

Read More

Difference Between dispose() and finalize() in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 1K+ Views

In this article, we will understand the difference between the Dispose() and Finalize() methods in C#. Both methods are used for resource cleanup, but they serve different purposes and are invoked in different ways during the object lifecycle. The Dispose() method provides deterministic cleanup where you control exactly when resources are freed, while Finalize() provides a safety net for cleanup that runs during garbage collection. Syntax Following is the syntax for implementing Dispose() method − public class MyClass : IDisposable { public void Dispose() { // ...

Read More

Difference Between Delegates and Events in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 2K+ Views

In C#, both delegates and events are used for callback mechanisms, but they serve different purposes and have distinct characteristics. Understanding their differences is crucial for proper C# programming and design patterns. Delegates A delegate is a type that represents references to methods with a specific signature. It acts as a function pointer that can hold references to one or more methods during runtime. Syntax public delegate returnType DelegateName(parameters); Example using System; public delegate void MyDelegate(string message); public class DelegateExample { public static void Method1(string ...

Read More

What is the usage of ref, out, and in keywords in C#?

Akshay Khot
Akshay Khot
Updated on 17-Mar-2026 653 Views

In C#, method parameters can be passed using different modifiers that control how arguments are handled. The ref, out, and in keywords allow you to pass parameters by reference rather than by value, each serving different purposes and having specific rules. By default, C# passes arguments by value, meaning a copy of the value is created. Changes made inside the method don't affect the original variable. Default Parameter Passing (By Value) Value Types When passing value types, a copy is made and modifications inside the method don't affect the original variable − using System; ...

Read More

What is the purpose of the StringBuilder class in C#?

Akshay Khot
Akshay Khot
Updated on 17-Mar-2026 597 Views

In C#, strings are immutable, meaning you cannot modify a string once it's created. Any modification returns a new string containing the changes, leaving the original intact. The StringBuilder class provides a mutable alternative for efficient string manipulation when you need to perform multiple modifications. String Immutability Example using System; class Program { static void Main(string[] args) { string word = "aaabbbccc"; string newWord = word.Replace('b', 'd'); Console.WriteLine(word); ...

Read More

System.Reflection namespace in C#

Akshay Khot
Akshay Khot
Updated on 17-Mar-2026 689 Views

The System.Reflection namespace in C# provides classes and interfaces that allow you to examine and interact with assemblies, modules, types, and members at runtime. This powerful feature enables reflection — the ability to inspect and manipulate code dynamically during execution. The Assembly class is central to this namespace, representing a loaded assembly in memory. You can access an assembly through a type's Assembly property or load it dynamically using various methods. Assembly Identity Components An assembly's identity consists of four key components − Simple name − the filename without the extension Version − from the ...

Read More
Showing 7441–7450 of 21,090 articles
« Prev 1 743 744 745 746 747 2109 Next »
Advertisements