Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Articles by Nizamuddin Siddiqui
Page 17 of 196
What are Local functions in C# 7.0?
Local functions are private methods defined inside another member (method, constructor, or property). They are only accessible within their containing member and provide a clean way to break down complex logic into smaller, reusable pieces without exposing helper methods to the entire class. Local functions were introduced in C# 7.0 and offer better performance than lambda expressions for recursive scenarios and provide compile-time checking for definite assignment. Syntax Following is the syntax for declaring a local function − returnType LocalFunctionName(parameters) { // function body } Local functions can be ...
Read MoreWhat is the implicit implementation of the interface and when to use implicit implementation of the interface in C#?
C# interface members can be implemented in two ways: implicitly and explicitly. With implicit implementation, the implementing class doesn't include the interface name before the member name, making the compiler infer the interface connection automatically. In implicit implementation, the members are exposed as public and are accessible when the object is cast as either the concrete type or the interface type. This approach is simpler and more commonly used when there are no naming conflicts between interface methods. Syntax Following is the syntax for implicit interface implementation − interface IInterfaceName { void ...
Read MoreHow to use ViewBag in ASP .Net MVC C#?
ViewBag uses the dynamic feature that was introduced in 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 vice-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. Syntax Following is the syntax for storing data in ViewBag − ...
Read MoreWhat are binary literals and digit separators in C# 7.0?
C# 7.0 introduced two important enhancements to numeric literals that improve code readability and provide new ways to represent numbers: binary literals and digit separators. These features make it easier to work with binary values and large numbers in your code. Binary Literals Before C# 7.0, you could only assign decimal and hexadecimal values to variables. Binary literals allow you to directly assign binary values using the 0b or 0B prefix, making it easier to work with bit flags, masks, and other binary operations. Syntax var binaryNumber = 0b10101010; // Binary literal var binaryNumber2 ...
Read MoreWhat is the significance of NonActionAttribute in ASP .Net MVC C#?
The NonAction attribute in ASP.NET MVC is used to prevent public methods in a controller from being treated as action methods. By default, all public methods in an MVC controller are accessible via URL routing. The NonAction attribute allows you to keep methods public (for internal use within the controller or class hierarchy) while blocking direct HTTP access. Syntax Following is the syntax for applying the NonAction attribute − [NonAction] public ReturnType MethodName() { // method implementation } Why Use NonAction Attribute In ASP.NET MVC, the framework automatically treats ...
Read MoreWhat are Ref locals and Ref returns in C# 7.0?
C# 7.0 introduced ref locals and ref returns, which allow methods to return references to variables instead of copies of their values. This enables direct modification of the original data through the returned reference. A ref return allows a method to return a reference to a variable, and the caller can create a ref local variable that directly references the returned memory location. Syntax Following is the syntax for declaring a ref return method − public static ref ReturnType MethodName(parameters) { return ref variable; } Following is the syntax ...
Read MoreWhat are the three segments of the default route, that is present in ASP .Net MVCnC#?
The ASP.NET MVC Routing module is responsible for mapping incoming browser requests to particular MVC controller actions. When the ASP.NET MVC application launches, it registers one or more patterns with the framework's route table to tell the routing engine what to do with any requests that match those patterns. When the routing engine receives a request at runtime, it matches that request's URL against the URL patterns registered with it and gives the response according to a pattern match. ASP.NET introduced Routing to eliminate the need of mapping each URL with a physical file. Routing enables us to define ...
Read MoreWhat are the levels at which filters can be applied in ASP .Net MVC C#?
In an ASP.NET MVC application, filters can be applied at three different levels to control the behavior of controllers and action methods. These levels determine the scope of filter application, from specific methods to the entire application. Action Method Level − Applies only to a specific action method Controller Level − Applies to all action methods within a controller Global Level − Applies to all controllers and action methods in the application Filter Application Levels Global Level Controller Level ...
Read MoreHow to use indexers in C# 8.0?
Indexers in C# allow objects to be accessed like arrays using the square bracket notation. C# 8.0 introduced the index from end operator (^) which provides a more intuitive way to access elements from the end of a collection or sequence. The ^ operator returns an index that is relative to the end of the sequence, making it the most compact and easiest way to access end elements compared to traditional methods like array.Length - 1. Syntax Following is the syntax for defining an indexer in a class − public returnType this[parameterType parameter] { ...
Read MoreWhat is the use of ChildActionOnly attribute in ASP .Net MVC C#?
The ChildActionOnly attribute in ASP.NET MVC C# restricts an action method to be accessible only through child requests from views using Html.Action() or Html.RenderAction() helpers. It prevents direct URL access to the action method, making it ideal for creating reusable partial components. Syntax Following is the syntax for using the ChildActionOnly attribute − [ChildActionOnly] public ActionResult ActionName() { // action logic return View(); } To invoke a child action from a view, use one of these helper methods − @Html.Action("ActionName", new { parameter = value }) ...
Read More