Csharp Articles

Page 68 of 196

What is the difference between All and Any in C# Linq?

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

The Any() and All() methods are LINQ extension methods that return bool values based on predicate conditions. Any() returns true if at least one element matches the predicate, while All() returns true only if every element matches the predicate. Both methods provide overloads − one that accepts a predicate and another parameterless version that simply checks if the collection contains any elements. Syntax Following is the syntax for Any() method − bool result = collection.Any(); bool result = collection.Any(predicate); Following is the syntax for All() method − bool result = collection.All(predicate); ...

Read More

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 591 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 347 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 652 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

How to open a browser window in full screen using Selenium WebDriver with C#?

Debomita Bhattacharjee
Debomita Bhattacharjee
Updated on 17-Mar-2026 2K+ Views

We can open a browser window in full screen using Selenium WebDriver in C# by using the Maximize() method. This method is applied on the WebDriver object through the window management interface and expands the browser to fill the entire screen. Syntax Following is the syntax for maximizing a browser window − driver.Manage().Window.Maximize(); For setting specific window size, you can also use − driver.Manage().Window.Size = new Size(width, height); Using Maximize() Method The Maximize() method is the most common approach to open a browser in full screen mode. It automatically ...

Read More

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

Akshay Khot
Akshay Khot
Updated on 17-Mar-2026 648 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
Showing 671–680 of 1,951 articles
« Prev 1 66 67 68 69 70 196 Next »
Advertisements