Difference Between FromBody and FromUri Attributes in C# ASP.NET WebAPI

Nizamuddin Siddiqui
Updated on 19-Aug-2020 11:46:27

6K+ Views

When the ASP.NET Web API calls a method on a controller, it must set values for the parameters, a process called parameter binding.In order to bind a model (an action parameter), that would normally default to a formatter, from the URI we need to decorate it with [FromUri] attribute. FromUriAttribute simply inherits from ModelBinderAttribute, providing us a shortcut directive to instruct Web API to grab specific parameters from the URI using the ValueProviders defined in the IUriValueProviderFactory. The attribute itself is sealed and cannot be extended any further, but you add as many custom IUriValueProviderFactories as you wish.The [FromBody] attribute ... Read More

Find Distance Covered to Collect Items at Equal Distances in Python

Arnab Chakraborty
Updated on 19-Aug-2020 11:45:08

111 Views

Suppose one race is going to be organized. Where different stones are placed on a road. One bucket is present at the starting point of the race, this is 6 units away from the first stone. The other stones are 4 units apart from each other and lie straight in a line one after another. Now, the participants start from the bucket, then collects the nearest stone, comes back and puts that stone into the bucket, after that runs again to collect the next nearest stone, runs back, and puts it in the bucket. This process will be continued until ... Read More

Find Direction from Given String in C++

Arnab Chakraborty
Updated on 19-Aug-2020 11:43:42

698 Views

Suppose we have a string which contains only L and R, this denotes left rotation and right rotation respectively, we have to find the final direction of pivot. Here directions are north(N), east(E), south(S) and west(W). We are assuming that the pivot is pointed towards north(N) in a compass.So, if the input is like "RRLRLLR", then the output will be E, as initial direction is N, RR will point to S, then LR will point to the same N again, then LL will point to previous position N, then R will point to E. So E is the final.To solve ... Read More

Count Substrings That Can Form Given Word in Python

Arnab Chakraborty
Updated on 19-Aug-2020 11:41:47

267 Views

Suppose we have a string S (all letters are in lowercase), we have to find the count of all of the sub-strings of length four whose characters can be rearranged to form this word "bird".So, if the input is like "birdb", then the output will be 2.To solve this, we will follow these steps −cnt := 0for i in range 0 to size of s - 3, dobird := an array with [0, 0, 0, 0]for j in range i to i + 4, doif s[j] is same as 'b', thenbird[0] := bird[0] + 1otherwise when s[j] is same as ... Read More

Difference Between Task.WhenAll and Task.WaitAll in C#

Nizamuddin Siddiqui
Updated on 19-Aug-2020 11:40:59

8K+ Views

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 completed.If we are using Task.WhenAll we will get a task object that isn’t complete. However, it will not block but will allow the program to execute. On the contrary, the Task.WaitAll method call actually blocks and waits for all other tasks to complete.To understand with an example, let us say we have a task that performs some activity with the UI thread say some animation needs ... Read More

Count Palindromic Substrings in Sorted String using Python

Arnab Chakraborty
Updated on 19-Aug-2020 11:39:50

205 Views

Suppose we have a string of lowercase characters (all are ASCII characters), we have to find all distinct continuous palindromic sub-strings of the given string.So, if the input is like "level", then the output will be 7 as there are seven substrings ['level', 'eve', 'l', 'e', 'v', 'e', 'l'].To solve this, we will follow these steps −N := 26n := length of strsum := 0my_map := a list of size N and fill with 0for i in range 0 to n, domy_map[ASCII of (str[i]) - ASCII of ('a') ] := my_map[ASCII of (str[i]) - ASCII of ('a') ] + 1for ... Read More

Find Coordinates of the Fourth Vertex of a Rectangle in Python

Arnab Chakraborty
Updated on 19-Aug-2020 11:38:04

746 Views

Suppose we have a grid of size Q * P, this grid contains exactly three asterisk '*' and every other cell there is dot '.', where '*' is for a vertex of a rectangle. We have to find the coordinates of the missing vertex. Here we will consider 1-based indexing.So, if the input is like grid = [ ".*.", "...", "*.*" ], then the output will be [1, 3], this is the missing coordinate.To solve this, we will follow these steps −p := number of rowsq := number of columnsrow := make a map for all row number, and associated ... Read More

Download a File from a URL in C#

Nizamuddin Siddiqui
Updated on 19-Aug-2020 11:37:22

9K+ Views

A file can be downloaded from a URL using web client. It is available in 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 web client can be said as an application or web browser (like Google Chrome, Internet Explorer, Opera, Firefox, Safari) which is installed in a computer and used to interact with Web servers upon user’s request. It is basically a consumer application which collects processed data from servers.A Client and a Server are two parts of a connection, these are two ... Read More

Populate XDocument from String in C#

Nizamuddin Siddiqui
Updated on 19-Aug-2020 11:35:17

2K+ Views

XML is a self-describing language and it gives the data as well as the rules to identify what information it contains. Like HTML, XML is a subset of SGML - Standard Generalized Markup Language.The XDocument class contains the information necessary for a valid XML document. This includes an XML declaration, processing instructions, and comments.Note that we only have to create XDocument objects if we require the specific functionality provided by the XDocument class. In many circumstances, we can work directly with XElement. Working directly with XElement is a simpler programming model.XDocument derives from XContainer. Therefore, it can contain child nodes. ... Read More

Get the Name of the Current Executable in C#

Nizamuddin Siddiqui
Updated on 19-Aug-2020 11:31:26

5K+ Views

There are several ways to get the name of the current executable in C#.Using System.AppDomain −Application domain provides isolation between code running in different app domains. App Domain is a logical container for code and data just like process and has separate memory space and access to resources. App domain also serves as a boundary like process does to avoid any accidental or illegal attempts to access the data of an object in one running application from another.System.AppDomain class provides us the ways to deal with application domain. It provides methods to create new application domain, unload domain from memory ... Read More

Advertisements