Nizamuddin Siddiqui has Published 2303 Articles

How to force garbage collection in C#?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 19-Aug-2020 13:24:11

2K+ Views

Yes it is possible to force garbage collector in C# to run by calling Collect() methodThis is not considered a good practice because this might create a performance over head. Collect() Forces an immediate garbage collection of all generations.Collect(Int32)Forces an immediate garbage collection from generation 0 through a specified generation.Example Live ... Read More

How to create an array with non-default repeated values in C#?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 19-Aug-2020 13:19:46

786 Views

We can create an array with non-default values using Enumerable.Repeat(). It repeated a collection with repeated elements in C#. Firstly, set which element you want to repeat and how many times.Example 1class Program{    static void Main(string[] args){       var values = Enumerable.Repeat(10, 5);       foreach ... Read More

How to make use of both Take and Skip operator together in LINQ C# Programming

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 19-Aug-2020 13:18:01

189 Views

We are creating two instances of the Employee class, e and e1. The e is assigned to e1. Both objects are pointing to the same reference, hence we will get true as expected output for all the Equals.In the second case we can observe that, even though properties values are ... Read More

How to make use of both Take and Skip operator together in LINQ C#?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 19-Aug-2020 13:15:01

3K+ Views

The Take operator is used to return a given number of elements from an array and the Skip operator skips over a specified number of elements from an array.Skip, skips elements up to a specified position starting from the first element in a sequence.Take, takes elements up to a specified ... Read More

What is Shallow Copy and how it is different from Deep Copy in C#?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 19-Aug-2020 12:59:31

1K+ Views

Shallow Copy −A shallow copy of an object copies the "main" object, but doesn’t copy the inner objects.The "inner objects" are shared between the original object and its copy.The problem with the shallow copy is that the two objects are not independent. If you modify the one object, the change ... Read More

How can we create a LOG filter for Logging purposes in C# ASP.NET WebAPI?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 19-Aug-2020 12:56:34

1K+ Views

Action filters are used to add extra logic before or after action methods execution. The OnActionExecuting and OnActionExecuted methods are used to add our logic before and after an action method is executed.Let us create create a LogAttribute that implemets ActionFilterAttribute which logs some information before and after action method ... Read More

How to do versioning with custom media type in C# ASP.NET WebAPI?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 19-Aug-2020 12:52:13

316 Views

Media types allow an API to inform the client how to interpret the data in the payload. In the HTTP protocol, Media Types are specified with identifiers like text/html, application/json, and application/xml, which correspond to HTML, JSON, and XML respectively, the most common web formats. There are other more APIspecific ... Read More

How to do versioning with accept header in C# ASP.NET WebAPI?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 19-Aug-2020 12:45:22

658 Views

The Accept header tells the server in what file format the browser wants the data. These file formats are more commonly called as MIME-types. MIME stands for Multipurpose Internet Mail Extensions.Versioning can be send in Headers like below.Version=1 StudentsV1Controller Version=2 StudentsV2ControllerSince we have not handled the version in accept headers, ... Read More

How can we create an exception filter to handle unhandled exceptions in C#ASP.NET WebAPI?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 19-Aug-2020 12:37:03

488 Views

An exception filter is executed when a controller method throws any unhandled exception that is not an HttpResponseException exception. The HttpResponseException type is a special case, because it is designed specifically for returning an HTTP response.Exception filters implement the System.Web.Http.Filters.IExceptionFilter interface. The simplest way to write an exception filter is ... Read More

How to do versioning with the Querystring parameter in C# ASP.NET WebAPI?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 19-Aug-2020 12:32:59

486 Views

The DefaultHttpControllerSelector class in web api is responsible for selecting the appropriate controller action method that we send in the URI.Say we have to implement versioning in the query string like belowv=1 StudentsV1Controller (Version 1) v=2 StudentsV2Controller (Version 2)If we pass the versioning information in the query string like http://localhost:58174/api/student?v=1 ... Read More

Advertisements