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

Nizamuddin Siddiqui
Published on 05-Dec-2020 11:15:12
With INNER JOIN only the matching elements are included in the result set. Non-matching elements are excluded from the result set.With LEFT OUTER JOIN all the matching elements + all the non-matching elements from the left collection are included in the result set.Let us understand implementing Left Outer Join with an example. ... Read More

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

Nizamuddin Siddiqui
Published on 05-Dec-2020 11:13:30
Reflection is the process of describing the metadata of types, methods and fields in a code. The namespace System.Reflection enables you to obtain data about the loaded assemblies, the elements within them like classes, methods and value types. There are numerous classes of System.Reflection but the most commonly used ones ... Read More

How to implement dependency injection using Interface-based injection in C#?

Nizamuddin Siddiqui
Published on 05-Dec-2020 11:12:30
The process of injecting (converting) coupled (dependent) objects into decoupled (independent) objects is called Dependency Injection.Types of Dependency InjectionThere are four types of DI −Constructor InjectionSetter InjectionInterface-based injectionService Locator InjectionInterface InjectionInterface Injection is similar to Getter and Setter DI, the Getter, and Setter DI use default getter and setter but ... Read More

How to implement Dependency Injection using Property in C#?

Nizamuddin Siddiqui
Published on 05-Dec-2020 11:10:45
The process of injecting (converting) coupled (dependent) objects into decoupled (independent) objects is called Dependency Injection.Types of Dependency InjectionThere are four types of DI −Constructor InjectionSetter InjectionInterface-based injectionService Locator InjectionSetter InjectionGetter and Setter Injection injects the dependency by using default public properties procedure such as Gettter(get(){}) and Setter(set(){}). Examplepublic interface IService{ ... Read More

How to implement Open Closed principle using C#?

Nizamuddin Siddiqui
Published on 05-Dec-2020 11:09:33
Software entities like classes, modules and functions should be open for extension but closed for modifications.Definition − The Open Close Principle states that the design and writing of the code should be done in a way that new functionality should be added with minimum changes in the existing code. The ... Read More

How to implement Single Responsibility Principle using C#?

Nizamuddin Siddiqui
Published on 05-Dec-2020 11:07:11
A class should have only one reason to change.Definition − In this context, responsibility is considered to be one reason to change.This principle states that if we have 2 reasons to change for a class, we have to split the functionality in two classes. Each class will handle only one ... Read More

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

Nizamuddin Siddiqui
Published on 05-Dec-2020 11:04:40
Use Namespace Newtonsoft.Json.Formatting Newtonsoft.Json.Formatting provides formatting options to Format the JsonNone − No special formatting is applied. This is the default.Indented − Causes child objects to be indented according to the Newtonsoft.Json.JsonTextWriter.Indentation and Newtonsoft.Json.JsonTextWriter.IndentChar settings.Examplestatic void Main(string[] args){    Product product = new Product{       Name = "Apple", ... Read More

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

Nizamuddin Siddiqui
Published on 05-Dec-2020 11:02:37
The Task.WaitAll blocks the current thread until all other tasks have completed execution.The Task.WhenAll method is used to create a task that will complete if and only if all the other tasks have complete. In the 1st example, we could see that when using Task.WhenAll the task complete is executed ... Read More

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

Nizamuddin Siddiqui
Published on 05-Dec-2020 11:00:39
Any(<predicate>) method returns true if at least one of the elements in the source sequence matches the provided predicate. Otherwise, it returns false. On the other hand, the All(<predicate>) method returns true if every element in the source sequence matches the provided predicate. Otherwise, it returns falseExamplestatic void Main(string[] args){ ... Read More

What is dependency inversion principle and how to implement in C#?

Nizamuddin Siddiqui
Published on 05-Dec-2020 10:58:55
High-level modules should not depend on low-level modules. Both should depend on abstractions.Abstractions should not depend on details. Details should depend on abstractions.This principle is primarily concerned with reducing dependencies among the code modules.ExampleCode Before Dependency Inversionusing System; namespace SolidPrinciples.Dependency.Invertion.Before{    public class Email{       public string ToAddress ... Read More
1 2 3 4 5 6 7 ... 4315 Next
Advertisements