Found 33676 Articles for Programming

What is the significance of NonActionAttribute in ASP .Net MVC C#?

Nizamuddin Siddiqui
Updated on 24-Sep-2020 11:10:35

4K+ Views

The NonAction attribute is used when we want a public method in a controller but do not want to treat it as an action method. An action method is a public method in a controller that can be invoked using a URL. So, by default, if we have any public method in a controller then it can be invoked using a URL request. To restrict access to public methods in a controller, NonAction attribute can be used.Now let us consider HomeController having two public methods MyMethod1 and MyMethod2.ControllerExampleusing System.Web.Mvc; namespace DemoMvcApplication.Controllers{    public class HomeController : Controller{       ... Read More

How to use ViewBag in ASP .Net MVC C#?

Nizamuddin Siddiqui
Updated on 24-Sep-2020 11:07:44

4K+ Views

ViewBag uses the dynamic feature that was introduced in to C# 4.0. It allows an object to have properties dynamically added to it. Internally, it is a dynamic type property of the ControllerBase class which is the base class of the Controller class.ViewBag only transfers data from controller to view, not visa-versa. ViewBag values will be null if redirection occurs. ViewBag is able to set and get value dynamically and able to add any number of additional fields without converting it to strongly typed.Storing data in ViewBag −ViewBag.Counties = countriesList;Retrieving data from ViewBag −string country = ViewBag.Countries;ControllerExampleusing System.Collections.Generic; using System.Web.Mvc; ... Read More

How to find and extract a number from a string in C#?

Nizamuddin Siddiqui
Updated on 24-Sep-2020 10:59:04

13K+ Views

A regular expression is a pattern that could be matched against an input text. The .Net framework provides a regular expression engine that allows such matching. A pattern consists of one or more character literals, operators, or constructs.Here are basic pattern metacharacters used by RegEx −* = zero or more ? = zero or one ^ = not [] = rangeThe ^ symbol is used to specify not condition.the [] brackets if we are to give range values such as 0 - 9 or a-z or A-ZUsing Char.IsDigit()Example Live Demousing System; namespace DemoApplication{    public class Program{       static ... Read More

What are built-in message handlers in Asp.Net webAPI C#?

Nizamuddin Siddiqui
Updated on 24-Sep-2020 10:55:19

756 Views

A message handler is a class that receives an HTTP request and returns an HTTP response. Message handlers derive from the abstract HttpMessageHandler class. Message handlers provide us the opportunity to process, edit, or decline an incoming request before it reaches the HttpControllerDispatcher.Message handlers are executed much earlier in the request processing pipeline, hence they are a great place to implement cross cutting concerns in Web API. Message Handlers are nothing but a chain of classes (it may be system defined or defined by us) that sits next to the process of HTTP request and response through a pipeline.For example, ... Read More

Length of a Linked List in Python

SaiKrishna Tavva
Updated on 09-Oct-2024 14:27:37

7K+ Views

To calculate the length of a Linked list, we traverse the list, counting each node until we reach the end, where the next node is None. Suppose, we have a singly linked list, we have to find its length. The linked list has fields next and val. So, if the input is like [2 -> 4 -> 5 -> 7 -> 8 -> 9 -> 3], then the output will be 7. The two commonly used methods to find the length of a linked list are as follows - ... Read More

Latin Square in Python

Arnab Chakraborty
Updated on 21-Oct-2021 09:37:38

1K+ Views

The Latin square is a matrix that has a special pattern. Let's see different examples to examine the pattern.1 2 2 1 1 2 3 3 1 2 2 3 1 1 2 3 4 4 1 2 3 3 4 1 2 2 3 4 1 The Latin square that you get will be of different size as you notice in the above examples. But, if you carefully observe the above matrices' pattern, you will find out that the last number of the previous row comes as the first element of the next row.That's the pattern ... Read More

Largest product of contiguous digits in Python

Arnab Chakraborty
Updated on 23-Sep-2020 07:34:26

341 Views

Suppose we have two numbers num and k, we have to find the largest product of k contiguous digits in num. We have to keep in mind that num is guaranteed to have >= k digits.So, if the input is like num = 52689762 and k = 4, then the output will be 3024, largest product of 4 consecutive digits is (8*9*7*6) = 3024.To solve this, we will follow these steps −largest := 0cand := 1while (quotient of num/10)^(k-1) > 0, dodigits := (last digit of nums)^kcand := 1while digits > 0, docand := cand * (digits mod 10)if cand ... Read More

Largest Number By Two Times in Python

Arnab Chakraborty
Updated on 23-Sep-2020 07:32:53

287 Views

Suppose we have a list of numbers; we have to check whether the largest number is bigger than the second-largest number by more than two times. As an example, if the list is like [3, 9, 6], then it will return false, as 9 is not bigger than 12 (2 times 6). When the list is [6, 3, 15], it will return true, as 15 is bigger than 12 (2 times 6).To solve this, we will follow these steps −if size of nums < 2, thenreturn Falsep_max := minimum of nums[0] and nums[1]c_max := maximum of nums[0] and nums[1]for i ... Read More

Largest Gap in Python

Arnab Chakraborty
Updated on 23-Sep-2020 07:31:10

1K+ Views

Suppose we have a list of numbers called nums, we have to find the largest difference of two consecutive numbers in the sorted version of nums.So, if the input is like [5, 2, 3, 9, 10, 11], then the output will be 4, as the largest gap between 5 and 9 is 4.To solve this, we will follow these steps −n := sorted list numsans := a new listfor i in range 0 to size of n -2, doinsert n[i+1]-n[i] at the end of ansreturn maximum of ansLet us see the following implementation to get better understanding −Example Live Democlass Solution: ... Read More

K Prefix in Python

Arnab Chakraborty
Updated on 23-Sep-2020 07:29:49

441 Views

Suppose we have a list of numbers nums and an integer k, we have to find the maximum possible i where nums[0] + nums[1] + ... + nums[i] ≤ k. We will return -1 if no valid i exists.So, if the input is like nums = [4, -7, 5, 2, 6], k = 5, then the output will be 3, the index is 3 as if we add 4+(-7)+5+2 = 4, this is less than k, if we add last element it will no longer less than k, so the index is 3.To solve this, we will follow these steps ... Read More

Advertisements